//*Set Working Directory if needed*//
//* Should not need to be done if you are running the files   *//
//* per the instructions in the readme file  *//
/* cd Z:\Econ428_Sp15\Metelski\Documentation\Data\ */


//*******************************************************************//
//*******************************************************************//
//**************************Reducing Datasets************************//
//*******************************************************************//
//*******************************************************************//

//*******************************************************************//
//**************************Population Data**************************//
//*******************************************************************//

//********************************2006********************************//

//*import Census importable file*// 
	use Importable\census.dta, clear 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Age Groups Gender*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
keep if agegrp == 0
drop if sex == 1
drop if sex == 2
keep  popestimate2006 area_fips  

//*Rename Variables*//
rename popestimate2006 Totalpopestimate2006

//*Save Dataset*//
save Merge\2006pop.dta , replace   
clear 

//*Population by Gender*// 

//*Female 2006*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54
replace area_fips = subinstr(area_fips, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 1
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2006 area_fips  
reshape wide popestimate2006 , i(area_fips) j(agegrp) 

rename popestimate20065 Fpopestimate2006_20_24
rename popestimate20066 Fpopestimate2006_25_29
rename popestimate20067 Fpopestimate2006_30_34
rename popestimate20068 Fpopestimate2006_35_39
rename popestimate20069 Fpopestimate2006_40_44
rename popestimate200610 Fpopestimate2006_45_49
rename popestimate200611 Fpopestimate2006_50_54
rename popestimate200612 Fpopestimate2006_55_59
rename popestimate200613 Fpopestimate2006_60_64
rename popestimate200614 Fpopestimate2006_65_69


//*Save Dataset*//
save Merge\F2006reducedcensus.dta , replace   
clear 

//*Male 2006*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 2
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2006 area_fips  
reshape wide popestimate2006 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20065 Mpopestimate2006_20_24
rename popestimate20066 Mpopestimate2006_25_29
rename popestimate20067 Mpopestimate2006_30_34
rename popestimate20068 Mpopestimate2006_35_39
rename popestimate20069 Mpopestimate2006_40_44
rename popestimate200610 Mpopestimate2006_45_49
rename popestimate200611 Mpopestimate2006_50_54
rename popestimate200612 Mpopestimate2006_55_59
rename popestimate200613 Mpopestimate2006_60_64
rename popestimate200614 Mpopestimate2006_65_69

//*Save Dataset*//
save Merge\M2006reducedcensus.dta , replace   
clear 

//********************************2007********************************//


//*Female 2007*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 1
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2007 area_fips  
reshape wide popestimate2007 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20075 Fpopestimate2007_20_24
rename popestimate20076 Fpopestimate2007_25_29
rename popestimate20077 Fpopestimate2007_30_34
rename popestimate20078 Fpopestimate2007_35_39
rename popestimate20079 Fpopestimate2007_40_44
rename popestimate200710 Fpopestimate2007_45_49
rename popestimate200711 Fpopestimate2007_50_54
rename popestimate200712 Fpopestimate2007_55_59
rename popestimate200713 Fpopestimate2007_60_64
rename popestimate200714 Fpopestimate2007_65_69

//*Save Dataset*//
save Merge\F2007reducedcensus.dta , replace   
clear 

//*Male 2007*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 2
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2007 area_fips  
reshape wide popestimate2007 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20075 Mpopestimate2007_20_24
rename popestimate20076 Mpopestimate2007_25_29
rename popestimate20077 Mpopestimate2007_30_34
rename popestimate20078 Mpopestimate2007_35_39
rename popestimate20079 Mpopestimate2007_40_44
rename popestimate200710 Mpopestimate2007_45_49
rename popestimate200711 Mpopestimate2007_50_54
rename popestimate200712 Mpopestimate2007_55_59
rename popestimate200713 Mpopestimate2007_60_64
rename popestimate200714 Mpopestimate2007_65_69

//*Save Dataset*//
save Merge\M2007reducedcensus.dta , replace   
clear 

//********************************2008********************************//


//*Female 2008*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 1
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2008 area_fips  
reshape wide popestimate2008 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20085 Fpopestimate2008_20_24
rename popestimate20086 Fpopestimate2008_25_29
rename popestimate20087 Fpopestimate2008_30_34
rename popestimate20088 Fpopestimate2008_35_39
rename popestimate20089 Fpopestimate2008_40_44
rename popestimate200810 Fpopestimate2008_45_49
rename popestimate200811 Fpopestimate2008_50_54
rename popestimate200812 Fpopestimate2008_55_59
rename popestimate200813 Fpopestimate2008_60_64
rename popestimate200814 Fpopestimate2008_65_69

//*Save Dataset*//
save Merge\F2008reducedcensus.dta , replace   
clear 

//*Male 2008*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 2
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2008 area_fips  
reshape wide popestimate2008 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20085 Mpopestimate2008_20_24
rename popestimate20086 Mpopestimate2008_25_29
rename popestimate20087 Mpopestimate2008_30_34
rename popestimate20088 Mpopestimate2008_35_39
rename popestimate20089 Mpopestimate2008_40_44
rename popestimate200810 Mpopestimate2008_45_49
rename popestimate200811 Mpopestimate2008_50_54
rename popestimate200812 Mpopestimate2008_55_59
rename popestimate200813 Mpopestimate2008_60_64
rename popestimate200814 Mpopestimate2008_65_69

//*Save Dataset*//
save Merge\M2008reducedcensus.dta , replace   
clear 

//********************************2009********************************//


//*Female 2009*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 1
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2009 area_fips  
reshape wide popestimate2009 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20095 Fpopestimate2009_20_24
rename popestimate20096 Fpopestimate2009_25_29
rename popestimate20097 Fpopestimate2009_30_34
rename popestimate20098 Fpopestimate2009_35_39
rename popestimate20099 Fpopestimate2009_40_44
rename popestimate200910 Fpopestimate2009_45_49
rename popestimate200911 Fpopestimate2009_50_54
rename popestimate200912 Fpopestimate2009_55_59
rename popestimate200913 Fpopestimate2009_60_64
rename popestimate200914 Fpopestimate2009_65_69

//*Save Dataset*//
save Merge\F2009reducedcensus.dta , replace   
clear 

//*Male 2009*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 2
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2009 area_fips  
reshape wide popestimate2009 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20095 Mpopestimate2009_20_24
rename popestimate20096 Mpopestimate2009_25_29
rename popestimate20097 Mpopestimate2009_30_34
rename popestimate20098 Mpopestimate2009_35_39
rename popestimate20099 Mpopestimate2009_40_44
rename popestimate200910 Mpopestimate2009_45_49
rename popestimate200911 Mpopestimate2009_50_54
rename popestimate200912 Mpopestimate2009_55_59
rename popestimate200913 Mpopestimate2009_60_64
rename popestimate200914 Mpopestimate2009_65_69

//*Save Dataset*//
save Merge\M2009reducedcensus.dta , replace   
clear 

//********************************2010********************************//


//*Female 2010*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 1
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2010 area_fips  
reshape wide popestimate2010 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20105 Fpopestimate2010_20_24
rename popestimate20106 Fpopestimate2010_25_29
rename popestimate20107 Fpopestimate2010_30_34
rename popestimate20108 Fpopestimate2010_35_39
rename popestimate20109 Fpopestimate2010_40_44
rename popestimate201010 Fpopestimate2010_45_49
rename popestimate201011 Fpopestimate2010_50_54
rename popestimate201012 Fpopestimate2010_55_59
rename popestimate201013 Fpopestimate2010_60_64
rename popestimate201014 Fpopestimate2010_65_69

//*Save Dataset*//
save Merge\F2010reducedcensus.dta , replace   
clear 

//*Male 2010*// 

//*import Census importable file*// 
	use Importable\census.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if sex == 0
drop if sex == 2
drop state county stname ctyname sumlev

//*Create Variables for Each Age Group*//
keep agegrp popestimate2010 area_fips  
reshape wide popestimate2010 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20105 Mpopestimate2010_20_24
rename popestimate20106 Mpopestimate2010_25_29
rename popestimate20107 Mpopestimate2010_30_34
rename popestimate20108 Mpopestimate2010_35_39
rename popestimate20109 Mpopestimate2010_40_44
rename popestimate201010 Mpopestimate2010_45_49
rename popestimate201011 Mpopestimate2010_50_54
rename popestimate201012 Mpopestimate2010_55_59
rename popestimate201013 Mpopestimate2010_60_64
rename popestimate201014 Mpopestimate2010_65_69

//*Save Dataset*//
save Merge\M2010reducedcensus.dta , replace   
clear 

//********************************2011********************************//

//*2011 Male*// 

//*import Census importable file*// 
	use Importable\census2011.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
keep area_fips tot_male tot_female year agegrp
keep if year == 4 
drop if agegrp <= 4 
drop if agegrp >= 15

//*Create Variables for Each Age Group*//
keep agegrp tot_male area_fips 
reshape wide tot_male , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename tot_male5 Mpopestimate2011_20_24
rename tot_male6 Mpopestimate2011_25_29
rename tot_male7 Mpopestimate2011_30_34
rename tot_male8 Mpopestimate2011_35_39
rename tot_male9 Mpopestimate2011_40_44
rename tot_male10 Mpopestimate2011_45_49
rename tot_male11 Mpopestimate2011_50_54
rename tot_male12 Mpopestimate2011_55_59
rename tot_male13 Mpopestimate2011_60_64
rename tot_male14 Mpopestimate2011_65_69

//*Save Dataset*//
save Merge\M2011reducedcensus.dta , replace   
clear

//*2011 Female*// 

//*import Census importable file*// 
	use Importable\census2011.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Create FIPS Code Variable*// 
generate area_fips = subinstr(ctyname, "Adair County","21001",.) if state == 21
replace area_fips = subinstr(area_fips, "Allen County","21003",.) if state == 21
replace area_fips = subinstr(area_fips, "Anderson County","21005",.) if state == 21
replace area_fips = subinstr(area_fips, "Ballard County","21007",.) if state == 21
replace area_fips = subinstr(area_fips, "Barren County","21009",.) if state == 21
replace area_fips = subinstr(area_fips, "Bath County","21011",.) if state == 21
replace area_fips = subinstr(area_fips, "Bell County","21013",.) if state == 21
replace area_fips = subinstr(area_fips, "Boone County","21015",.) if state == 21
replace area_fips = subinstr(area_fips, "Bourbon County","21017",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyd County","21019",.) if state == 21
replace area_fips = subinstr(area_fips, "Boyle County","21021",.) if state == 21
replace area_fips = subinstr(area_fips, "Bracken County","21023",.) if state == 21
replace area_fips = subinstr(area_fips, "Breathitt County","21025",.) if state == 21
replace area_fips = subinstr(area_fips, "Breckinridge County","21027",.) if state == 21
replace area_fips = subinstr(area_fips, "Bullitt County","21029",.) if state == 21
replace area_fips = subinstr(area_fips, "Butler County","21031",.) if state == 21
replace area_fips = subinstr(area_fips, "Caldwell County","21033",.) if state == 21
replace area_fips = subinstr(area_fips, "Calloway County","21035",.) if state == 21
replace area_fips = subinstr(area_fips, "Campbell County","21037",.) if state == 21
replace area_fips = subinstr(area_fips, "Carlisle County","21039",.) if state == 21
replace area_fips = subinstr(area_fips, "Carroll County","21041",.) if state == 21
replace area_fips = subinstr(area_fips, "Carter County","21043",.) if state == 21
replace area_fips = subinstr(area_fips, "Casey County","21045",.) if state == 21
replace area_fips = subinstr(area_fips, "Christian County","21047",.) if state == 21
replace area_fips = subinstr(area_fips, "Clark County","21049",.) if state == 21
replace area_fips = subinstr(area_fips, "Clay County","21051",.) if state == 21
replace area_fips = subinstr(area_fips, "Clinton County","21053",.) if state == 21
replace area_fips = subinstr(area_fips, "Crittenden County","21055",.) if state == 21
replace area_fips = subinstr(area_fips, "Cumberland County","21057",.) if state == 21
replace area_fips = subinstr(area_fips, "Daviess County","21059",.) if state == 21
replace area_fips = subinstr(area_fips, "Edmonson County","21061",.) if state == 21
replace area_fips = subinstr(area_fips, "Elliott County","21063",.) if state == 21
replace area_fips = subinstr(area_fips, "Estill County","21065",.) if state == 21
replace area_fips = subinstr(area_fips, "Fayette County","21067",.) if state == 21
replace area_fips = subinstr(area_fips, "Fleming County","21069",.) if state == 21
replace area_fips = subinstr(area_fips, "Floyd County","21071",.) if state == 21
replace area_fips = subinstr(area_fips, "Franklin County","21073",.) if state == 21
replace area_fips = subinstr(area_fips, "Fulton County","21075",.) if state == 21
replace area_fips = subinstr(area_fips, "Gallatin County","21077",.) if state == 21
replace area_fips = subinstr(area_fips, "Garrard County","21079",.) if state == 21
replace area_fips = subinstr(area_fips, "Grant County","21081",.) if state == 21
replace area_fips = subinstr(area_fips, "Graves County","21083",.) if state == 21
replace area_fips = subinstr(area_fips, "Grayson County","21085",.) if state == 21
replace area_fips = subinstr(area_fips, "Green County","21087",.) if state == 21
replace area_fips = subinstr(area_fips, "Greenup County","21089",.) if state == 21
replace area_fips = subinstr(area_fips, "Hancock County","21091",.) if state == 21
replace area_fips = subinstr(area_fips, "Hardin County","21093",.) if state == 21
replace area_fips = subinstr(area_fips, "Harlan County","21095",.) if state == 21
replace area_fips = subinstr(area_fips, "Harrison County","21097",.) if state == 21
replace area_fips = subinstr(area_fips, "Hart County","21099",.) if state == 21
replace area_fips = subinstr(area_fips, "Henderson County","21101",.) if state == 21
replace area_fips = subinstr(area_fips, "Henry County","21103",.) if state == 21
replace area_fips = subinstr(area_fips, "Hickman County","21105",.) if state == 21
replace area_fips = subinstr(area_fips, "Hopkins County","21107",.) if state == 21
replace area_fips = subinstr(area_fips, "Jackson County","21109",.) if state == 21
replace area_fips = subinstr(area_fips, "Jefferson County","21111",.) if state == 21
replace area_fips = subinstr(area_fips, "Jessamine County","21113",.) if state == 21
replace area_fips = subinstr(area_fips, "Johnson County","21115",.) if state == 21
replace area_fips = subinstr(area_fips, "Kenton County","21117",.) if state == 21
replace area_fips = subinstr(area_fips, "Knott County","21119",.) if state == 21
replace area_fips = subinstr(area_fips, "Knox County","21121",.) if state == 21
replace area_fips = subinstr(area_fips, "Larue County","21123",.) if state == 21
replace area_fips = subinstr(area_fips, "Laurel County","21125",.) if state == 21
replace area_fips = subinstr(area_fips, "Lawrence County","21127",.) if state == 21
replace area_fips = subinstr(area_fips, "Lee County","21129",.) if state == 21
replace area_fips = subinstr(area_fips, "Leslie County","21131",.) if state == 21
replace area_fips = subinstr(area_fips, "Letcher County","21133",.) if state == 21
replace area_fips = subinstr(area_fips, "Lewis County","21135",.) if state == 21
replace area_fips = subinstr(area_fips, "Lincoln County","21137",.) if state == 21
replace area_fips = subinstr(area_fips, "Livingston County","21139",.) if state == 21
replace area_fips = subinstr(area_fips, "Logan County","21141",.) if state == 21
replace area_fips = subinstr(area_fips, "Lyon County","21143",.) if state == 21
replace area_fips = subinstr(area_fips, "McCracken County","21145",.) if state == 21
replace area_fips = subinstr(area_fips, "McCreary County","21147",.) if state == 21
replace area_fips = subinstr(area_fips, "McLean County","21149",.) if state == 21
replace area_fips = subinstr(area_fips, "Madison County","21151",.) if state == 21
replace area_fips = subinstr(area_fips, "Magoffin County","21153",.) if state == 21
replace area_fips = subinstr(area_fips, "Marion County","21155",.) if state == 21
replace area_fips = subinstr(area_fips, "Marshall County","21157",.) if state == 21
replace area_fips = subinstr(area_fips, "Martin County","21159",.) if state == 21
replace area_fips = subinstr(area_fips, "Mason County","21161",.) if state == 21
replace area_fips = subinstr(area_fips, "Meade County","21163",.) if state == 21
replace area_fips = subinstr(area_fips, "Menifee County","21165",.) if state == 21
replace area_fips = subinstr(area_fips, "Mercer County","21167",.) if state == 21
replace area_fips = subinstr(area_fips, "Metcalfe County","21169",.) if state == 21
replace area_fips = subinstr(area_fips, "Monroe County","21171",.) if state == 21
replace area_fips = subinstr(area_fips, "Montgomery County","21173",.) if state == 21
replace area_fips = subinstr(area_fips, "Morgan County","21175",.) if state == 21
replace area_fips = subinstr(area_fips, "Muhlenberg County","21177",.) if state == 21
replace area_fips = subinstr(area_fips, "Nelson County","21179",.) if state == 21
replace area_fips = subinstr(area_fips, "Nicholas County","21181",.) if state == 21
replace area_fips = subinstr(area_fips, "Ohio County","21183",.) if state == 21
replace area_fips = subinstr(area_fips, "Oldham County","21185",.) if state == 21
replace area_fips = subinstr(area_fips, "Owen County","21187",.) if state == 21
replace area_fips = subinstr(area_fips, "Owsley County","21189",.) if state == 21
replace area_fips = subinstr(area_fips, "Pendleton County","21191",.) if state == 21
replace area_fips = subinstr(area_fips, "Perry County","21193",.) if state == 21
replace area_fips = subinstr(area_fips, "Pike County","21195",.) if state == 21
replace area_fips = subinstr(area_fips, "Powell County","21197",.) if state == 21
replace area_fips = subinstr(area_fips, "Pulaski County","21199",.) if state == 21
replace area_fips = subinstr(area_fips, "Robertson County","21201",.) if state == 21
replace area_fips = subinstr(area_fips, "Rockcastle County","21203",.) if state == 21
replace area_fips = subinstr(area_fips, "Rowan County","21205",.) if state == 21
replace area_fips = subinstr(area_fips, "Russell County","21207",.) if state == 21
replace area_fips = subinstr(area_fips, "Scott County","21209",.) if state == 21
replace area_fips = subinstr(area_fips, "Shelby County","21211",.) if state == 21
replace area_fips = subinstr(area_fips, "Simpson County","21213",.) if state == 21
replace area_fips = subinstr(area_fips, "Spencer County","21215",.) if state == 21
replace area_fips = subinstr(area_fips, "Taylor County","21217",.) if state == 21
replace area_fips = subinstr(area_fips, "Todd County","21219",.) if state == 21
replace area_fips = subinstr(area_fips, "Trigg County","21221",.) if state == 21
replace area_fips = subinstr(area_fips, "Trimble County","21223",.) if state == 21
replace area_fips = subinstr(area_fips, "Union County","21225",.) if state == 21
replace area_fips = subinstr(area_fips, "Warren County","21227",.) if state == 21
replace area_fips = subinstr(area_fips, "Washington County","21229",.) if state == 21
replace area_fips = subinstr(area_fips, "Wayne County","21231",.) if state == 21
replace area_fips = subinstr(area_fips, "Webster County","21233",.) if state == 21
replace area_fips = subinstr(area_fips, "Whitley County","21235",.) if state == 21
replace area_fips = subinstr(area_fips, "Wolfe County","21237",.) if state == 21
replace area_fips = subinstr(area_fips, "Woodford County","21239",.) if state == 21
replace area_fips = subinstr(ctyname, "Adams County","39001",.) if state == 39
replace area_fips = subinstr(area_fips, "Allen County","39003",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashland County","39005",.) if state == 39
replace area_fips = subinstr(area_fips, "Ashtabula County","39007",.) if state == 39
replace area_fips = subinstr(area_fips, "Athens County","39009",.) if state == 39
replace area_fips = subinstr(area_fips, "Auglaize County","39011",.) if state == 39
replace area_fips = subinstr(area_fips, "Belmont County","39013",.) if state == 39
replace area_fips = subinstr(area_fips, "Brown County","39015",.) if state == 39
replace area_fips = subinstr(area_fips, "Butler County","39017",.) if state == 39
replace area_fips = subinstr(area_fips, "Carroll County","39019",.) if state == 39
replace area_fips = subinstr(area_fips, "Champaign County","39021",.) if state == 39
replace area_fips = subinstr(area_fips, "Clark County","39023",.) if state == 39
replace area_fips = subinstr(area_fips, "Clermont County","39025",.) if state == 39
replace area_fips = subinstr(area_fips, "Clinton County","39027",.) if state == 39
replace area_fips = subinstr(area_fips, "Columbiana County","39029",.) if state == 39
replace area_fips = subinstr(area_fips, "Coshocton County","39031",.) if state == 39
replace area_fips = subinstr(area_fips, "Crawford County","39033",.) if state == 39
replace area_fips = subinstr(area_fips, "Cuyahoga County","39035",.) if state == 39
replace area_fips = subinstr(area_fips, "Darke County","39037",.) if state == 39
replace area_fips = subinstr(area_fips, "Defiance County","39039",.) if state == 39
replace area_fips = subinstr(area_fips, "Delaware County","39041",.) if state == 39
replace area_fips = subinstr(area_fips, "Erie County","39043",.) if state == 39
replace area_fips = subinstr(area_fips, "Fairfield County","39045",.) if state == 39
replace area_fips = subinstr(area_fips, "Fayette County","39047",.) if state == 39
replace area_fips = subinstr(area_fips, "Franklin County","39049",.) if state == 39
replace area_fips = subinstr(area_fips, "Fulton County","39051",.) if state == 39
replace area_fips = subinstr(area_fips, "Gallia County","39053",.) if state == 39
replace area_fips = subinstr(area_fips, "Geauga County","39055",.) if state == 39
replace area_fips = subinstr(area_fips, "Greene County","39057",.) if state == 39
replace area_fips = subinstr(area_fips, "Guernsey County","39059",.) if state == 39
replace area_fips = subinstr(area_fips, "Hamilton County","39061",.) if state == 39
replace area_fips = subinstr(area_fips, "Hancock County","39063",.) if state == 39
replace area_fips = subinstr(area_fips, "Hardin County","39065",.) if state == 39
replace area_fips = subinstr(area_fips, "Harrison County","39067",.) if state == 39
replace area_fips = subinstr(area_fips, "Henry County","39069",.) if state == 39
replace area_fips = subinstr(area_fips, "Highland County","39071",.) if state == 39
replace area_fips = subinstr(area_fips, "Hocking County","39073",.) if state == 39
replace area_fips = subinstr(area_fips, "Holmes County","39075",.) if state == 39
replace area_fips = subinstr(area_fips, "Huron County","39077",.) if state == 39
replace area_fips = subinstr(area_fips, "Jackson County","39079",.) if state == 39
replace area_fips = subinstr(area_fips, "Jefferson County","39081",.) if state == 39
replace area_fips = subinstr(area_fips, "Knox County","39083",.) if state == 39
replace area_fips = subinstr(area_fips, "Lake County","39085",.) if state == 39
replace area_fips = subinstr(area_fips, "Lawrence County","39087",.) if state == 39
replace area_fips = subinstr(area_fips, "Licking County","39089",.) if state == 39
replace area_fips = subinstr(area_fips, "Logan County","39091",.) if state == 39
replace area_fips = subinstr(area_fips, "Lorain County","39093",.) if state == 39
replace area_fips = subinstr(area_fips, "Lucas County","39095",.) if state == 39
replace area_fips = subinstr(area_fips, "Madison County","39097",.) if state == 39
replace area_fips = subinstr(area_fips, "Mahoning County","39099",.) if state == 39
replace area_fips = subinstr(area_fips, "Marion County","39101",.) if state == 39
replace area_fips = subinstr(area_fips, "Medina County","39103",.) if state == 39
replace area_fips = subinstr(area_fips, "Meigs County","39105",.) if state == 39
replace area_fips = subinstr(area_fips, "Mercer County","39107",.) if state == 39
replace area_fips = subinstr(area_fips, "Miami County","39109",.) if state == 39
replace area_fips = subinstr(area_fips, "Monroe County","39111",.) if state == 39
replace area_fips = subinstr(area_fips, "Montgomery County","39113",.) if state == 39
replace area_fips = subinstr(area_fips, "Morgan County","39115",.) if state == 39
replace area_fips = subinstr(area_fips, "Morrow County","39117",.) if state == 39
replace area_fips = subinstr(area_fips, "Muskingum County","39119",.) if state == 39
replace area_fips = subinstr(area_fips, "Noble County","39121",.) if state == 39
replace area_fips = subinstr(area_fips, "Ottawa County","39123",.) if state == 39
replace area_fips = subinstr(area_fips, "Paulding County","39125",.) if state == 39
replace area_fips = subinstr(area_fips, "Perry County","39127",.) if state == 39
replace area_fips = subinstr(area_fips, "Pickaway County","39129",.) if state == 39
replace area_fips = subinstr(area_fips, "Pike County","39131",.) if state == 39
replace area_fips = subinstr(area_fips, "Portage County","39133",.) if state == 39
replace area_fips = subinstr(area_fips, "Preble County","39135",.) if state == 39
replace area_fips = subinstr(area_fips, "Putnam County","39137",.) if state == 39
replace area_fips = subinstr(area_fips, "Richland County","39139",.) if state == 39
replace area_fips = subinstr(area_fips, "Ross County","39141",.) if state == 39
replace area_fips = subinstr(area_fips, "Sandusky County","39143",.) if state == 39
replace area_fips = subinstr(area_fips, "Scioto County","39145",.) if state == 39
replace area_fips = subinstr(area_fips, "Seneca County","39147",.) if state == 39
replace area_fips = subinstr(area_fips, "Shelby County","39149",.) if state == 39
replace area_fips = subinstr(area_fips, "Stark County","39151",.) if state == 39
replace area_fips = subinstr(area_fips, "Summit County","39153",.) if state == 39
replace area_fips = subinstr(area_fips, "Trumbull County","39155",.) if state == 39
replace area_fips = subinstr(area_fips, "Tuscarawas County","39157",.) if state == 39
replace area_fips = subinstr(area_fips, "Union County","39159",.) if state == 39
replace area_fips = subinstr(area_fips, "Van Wert County","39161",.) if state == 39
replace area_fips = subinstr(area_fips, "Vinton County","39163",.) if state == 39
replace area_fips = subinstr(area_fips, "Warren County","39165",.) if state == 39
replace area_fips = subinstr(area_fips, "Washington County","39167",.) if state == 39
replace area_fips = subinstr(area_fips, "Wayne County","39169",.) if state == 39
replace area_fips = subinstr(area_fips, "Williams County","39171",.) if state == 39
replace area_fips = subinstr(area_fips, "Wood County","39173",.) if state == 39
replace area_fips = subinstr(area_fips, "Wyandot County","39175",.) if state == 39
replace area_fips = subinstr(ctyname, "Adams County","42001",.) if state == 42
replace area_fips = subinstr(area_fips, "Allegheny County","42003",.) if state == 42
replace area_fips = subinstr(area_fips, "Armstrong County","42005",.) if state == 42
replace area_fips = subinstr(area_fips, "Beaver County","42007",.) if state == 42
replace area_fips = subinstr(area_fips, "Bedford County","42009",.) if state == 42
replace area_fips = subinstr(area_fips, "Berks County","42011",.) if state == 42
replace area_fips = subinstr(area_fips, "Blair County","42013",.) if state == 42
replace area_fips = subinstr(area_fips, "Bradford County","42015",.) if state == 42
replace area_fips = subinstr(area_fips, "Bucks County","42017",.) if state == 42
replace area_fips = subinstr(area_fips, "Butler County","42019",.) if state == 42
replace area_fips = subinstr(area_fips, "Cambria County","42021",.) if state == 42
replace area_fips = subinstr(area_fips, "Cameron County","42023",.) if state == 42
replace area_fips = subinstr(area_fips, "Carbon County","42025",.) if state == 42
replace area_fips = subinstr(area_fips, "Centre County","42027",.) if state == 42
replace area_fips = subinstr(area_fips, "Chester County","42029",.) if state == 42
replace area_fips = subinstr(area_fips, "Clarion County","42031",.) if state == 42
replace area_fips = subinstr(area_fips, "Clearfield County","42033",.) if state == 42
replace area_fips = subinstr(area_fips, "Clinton County","42035",.) if state == 42
replace area_fips = subinstr(area_fips, "Columbia County","42037",.) if state == 42
replace area_fips = subinstr(area_fips, "Crawford County","42039",.) if state == 42
replace area_fips = subinstr(area_fips, "Cumberland County","42041",.) if state == 42
replace area_fips = subinstr(area_fips, "Dauphin County","42043",.) if state == 42
replace area_fips = subinstr(area_fips, "Delaware County","42045",.) if state == 42
replace area_fips = subinstr(area_fips, "Elk County","42047",.) if state == 42
replace area_fips = subinstr(area_fips, "Erie County","42049",.) if state == 42
replace area_fips = subinstr(area_fips, "Fayette County","42051",.) if state == 42
replace area_fips = subinstr(area_fips, "Forest County","42053",.) if state == 42
replace area_fips = subinstr(area_fips, "Franklin County","42055",.) if state == 42
replace area_fips = subinstr(area_fips, "Fulton County","42057",.) if state == 42
replace area_fips = subinstr(area_fips, "Greene County","42059",.) if state == 42
replace area_fips = subinstr(area_fips, "Huntingdon County","42061",.) if state == 42
replace area_fips = subinstr(area_fips, "Indiana County","42063",.) if state == 42
replace area_fips = subinstr(area_fips, "Jefferson County","42065",.) if state == 42
replace area_fips = subinstr(area_fips, "Juniata County","42067",.) if state == 42
replace area_fips = subinstr(area_fips, "Lackawanna County","42069",.) if state == 42
replace area_fips = subinstr(area_fips, "Lancaster County","42071",.) if state == 42
replace area_fips = subinstr(area_fips, "Lawrence County","42073",.) if state == 42
replace area_fips = subinstr(area_fips, "Lebanon County","42075",.) if state == 42
replace area_fips = subinstr(area_fips, "Lehigh County","42077",.) if state == 42
replace area_fips = subinstr(area_fips, "Luzerne County","42079",.) if state == 42
replace area_fips = subinstr(area_fips, "Lycoming County","42081",.) if state == 42
replace area_fips = subinstr(area_fips, "McKean County","42083",.) if state == 42
replace area_fips = subinstr(area_fips, "Mercer County","42085",.) if state == 42
replace area_fips = subinstr(area_fips, "Mifflin County","42087",.) if state == 42
replace area_fips = subinstr(area_fips, "Monroe County","42089",.) if state == 42
replace area_fips = subinstr(area_fips, "Montgomery County","42091",.) if state == 42
replace area_fips = subinstr(area_fips, "Montour County","42093",.) if state == 42
replace area_fips = subinstr(area_fips, "Northampton County","42095",.) if state == 42
replace area_fips = subinstr(area_fips, "Northumberland County","42097",.) if state == 42
replace area_fips = subinstr(area_fips, "Perry County","42099",.) if state == 42
replace area_fips = subinstr(area_fips, "Philadelphia County","42101",.) if state == 42
replace area_fips = subinstr(area_fips, "Pike County","42103",.) if state == 42
replace area_fips = subinstr(area_fips, "Potter County","42105",.) if state == 42
replace area_fips = subinstr(area_fips, "Schuylkill County","42107",.) if state == 42
replace area_fips = subinstr(area_fips, "Snyder County","42109",.) if state == 42
replace area_fips = subinstr(area_fips, "Somerset County","42111",.) if state == 42
replace area_fips = subinstr(area_fips, "Sullivan County","42113",.) if state == 42
replace area_fips = subinstr(area_fips, "Susquehanna County","42115",.) if state == 42
replace area_fips = subinstr(area_fips, "Tioga County","42117",.) if state == 42
replace area_fips = subinstr(area_fips, "Union County","42119",.) if state == 42
replace area_fips = subinstr(area_fips, "Venango County","42121",.) if state == 42
replace area_fips = subinstr(area_fips, "Warren County","42123",.) if state == 42
replace area_fips = subinstr(area_fips, "Washington County","42125",.) if state == 42
replace area_fips = subinstr(area_fips, "Wayne County","42127",.) if state == 42
replace area_fips = subinstr(area_fips, "Westmoreland County","42129",.) if state == 42
replace area_fips = subinstr(area_fips, "Wyoming County","42131",.) if state == 42
replace area_fips = subinstr(area_fips, "York County","42133",.) if state == 42
replace area_fips = subinstr(ctyname, "Barbour County","54001",.) if state == 54
replace area_fips = subinstr(area_fips, "Berkeley County","54003",.) if state == 54
replace area_fips = subinstr(area_fips, "Boone County","54005",.) if state == 54
replace area_fips = subinstr(area_fips, "Braxton County","54007",.) if state == 54
replace area_fips = subinstr(area_fips, "Brooke County","54009",.) if state == 54
replace area_fips = subinstr(area_fips, "Cabell County","54011",.) if state == 54
replace area_fips = subinstr(area_fips, "Calhoun County","54013",.) if state == 54
replace area_fips = subinstr(area_fips, "Clay County","54015",.) if state == 54
replace area_fips = subinstr(area_fips, "Doddridge County","54017",.) if state == 54
replace area_fips = subinstr(area_fips, "Fayette County","54019",.) if state == 54
replace area_fips = subinstr(area_fips, "Gilmer County","54021",.) if state == 54
replace area_fips = subinstr(area_fips, "Grant County","54023",.) if state == 54
replace area_fips = subinstr(area_fips, "Greenbrier County","54025",.) if state == 54
replace area_fips = subinstr(area_fips, "Hampshire County","54027",.) if state == 54
replace area_fips = subinstr(area_fips, "Hancock County","54029",.) if state == 54
replace area_fips = subinstr(area_fips, "Hardy County","54031",.) if state == 54
replace area_fips = subinstr(area_fips, "Harrison County","54033",.) if state == 54
replace area_fips = subinstr(area_fips, "Jackson County","54035",.) if state == 54
replace area_fips = subinstr(area_fips, "Jefferson County","54037",.) if state == 54
replace area_fips = subinstr(area_fips, "Kanawha County","54039",.) if state == 54
replace area_fips = subinstr(area_fips, "Lewis County","54041",.) if state == 54
replace area_fips = subinstr(area_fips, "Lincoln County","54043",.) if state == 54
replace area_fips = subinstr(area_fips, "Logan County","54045",.) if state == 54
replace area_fips = subinstr(area_fips, "McDowell County","54047",.) if state == 54
replace area_fips = subinstr(area_fips, "Marion County","54049",.) if state == 54
replace area_fips = subinstr(area_fips, "Marshall County","54051",.) if state == 54
replace area_fips = subinstr(area_fips, "Mason County","54053",.) if state == 54
replace area_fips = subinstr(area_fips, "Mercer County","54055",.) if state == 54
replace area_fips = subinstr(area_fips, "Mineral County","54057",.) if state == 54
replace area_fips = subinstr(area_fips, "Mingo County","54059",.) if state == 54
replace area_fips = subinstr(area_fips, "Monongalia County","54061",.) if state == 54
replace area_fips = subinstr(area_fips, "Monroe County","54063",.) if state == 54
replace area_fips = subinstr(area_fips, "Morgan County","54065",.) if state == 54
replace area_fips = subinstr(area_fips, "Nicholas County","54067",.) if state == 54
replace area_fips = subinstr(area_fips, "Ohio County","54069",.) if state == 54
replace area_fips = subinstr(area_fips, "Pendleton County","54071",.) if state == 54
replace area_fips = subinstr(area_fips, "Pleasants County","54073",.) if state == 54
replace area_fips = subinstr(area_fips, "Pocahontas County","54075",.) if state == 54
replace area_fips = subinstr(area_fips, "Preston County","54077",.) if state == 54
replace area_fips = subinstr(area_fips, "Putnam County","54079",.) if state == 54
replace area_fips = subinstr(area_fips, "Raleigh County","54081",.) if state == 54
replace area_fips = subinstr(area_fips, "Randolph County","54083",.) if state == 54
replace area_fips = subinstr(area_fips, "Ritchie County","54085",.) if state == 54
replace area_fips = subinstr(area_fips, "Roane County","54087",.) if state == 54
replace area_fips = subinstr(area_fips, "Summers County","54089",.) if state == 54
replace area_fips = subinstr(area_fips, "Taylor County","54091",.) if state == 54
replace area_fips = subinstr(area_fips, "Tucker County","54093",.) if state == 54
replace area_fips = subinstr(area_fips, "Tyler County","54095",.) if state == 54
replace area_fips = subinstr(area_fips, "Upshur County","54097",.) if state == 54
replace area_fips = subinstr(area_fips, "Wayne County","54099",.) if state == 54
replace area_fips = subinstr(area_fips, "Webster County","54101",.) if state == 54
replace area_fips = subinstr(area_fips, "Wetzel County","54103",.) if state == 54
replace area_fips = subinstr(area_fips, "Wirt County","54105",.) if state == 54
replace area_fips = subinstr(area_fips, "Wood County","54107",.) if state == 54
replace area_fips = subinstr(area_fips, "Wyoming County","54109",.) if state == 54

destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
keep area_fips tot_male tot_female year agegrp
keep if year == 4 
drop if agegrp <= 4 
drop if agegrp >= 15

//*Create Variables for Each Age Group*//
keep agegrp tot_female area_fips 
reshape wide tot_female , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename tot_female5 Fpopestimate2011_20_24
rename tot_female6 Fpopestimate2011_25_29
rename tot_female7 Fpopestimate2011_30_34
rename tot_female8 Fpopestimate2011_35_39
rename tot_female9 Fpopestimate2011_40_44
rename tot_female10 Fpopestimate2011_45_49
rename tot_female11 Fpopestimate2011_50_54
rename tot_female12 Fpopestimate2011_55_59
rename tot_female13 Fpopestimate2011_60_64
rename tot_female14 Fpopestimate2011_65_69

//*Save Dataset*//
save Merge\F2011reducedcensus.dta , replace   
clear

//********************************************************************//
//***************************State Level******************************//
//********************************************************************//

//*******************************2006*********************************//

//*Female*// 

//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 1

//*Create Variables for Each Age Group*//
keep agegrp popestimate2006 area_fips 
reshape wide popestimate2006 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20065 Fpopestimate2006_20_24
rename popestimate20066 Fpopestimate2006_25_29
rename popestimate20067 Fpopestimate2006_30_34
rename popestimate20068 Fpopestimate2006_35_39
rename popestimate20069 Fpopestimate2006_40_44
rename popestimate200610 Fpopestimate2006_45_49
rename popestimate200611 Fpopestimate2006_50_54
rename popestimate200612 Fpopestimate2006_55_59
rename popestimate200613 Fpopestimate2006_60_64
rename popestimate200614 Fpopestimate2006_65_69

//*Save Dataset*//
save Merge\F2006reducedcensusstate.dta , replace   
clear 

//*Male*// 

//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 2

//*Create Variables for Each Age Group*//
keep agegrp popestimate2006 area_fips 
reshape wide popestimate2006 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20065 Mpopestimate2006_20_24
rename popestimate20066 Mpopestimate2006_25_29
rename popestimate20067 Mpopestimate2006_30_34
rename popestimate20068 Mpopestimate2006_35_39
rename popestimate20069 Mpopestimate2006_40_44
rename popestimate200610 Mpopestimate2006_45_49
rename popestimate200611 Mpopestimate2006_50_54
rename popestimate200612 Mpopestimate2006_55_59
rename popestimate200613 Mpopestimate2006_60_64
rename popestimate200614 Mpopestimate2006_65_69

//*Save Dataset*//
save Merge\M2006reducedcensusstate.dta , replace   
clear 

//*******************************2007*********************************//

//*Female*//
//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 1

//*Create Variables for Each Age Group*//
keep agegrp popestimate2007 area_fips 
reshape wide popestimate2007 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20075 Fpopestimate2007_20_24
rename popestimate20076 Fpopestimate2007_25_29
rename popestimate20077 Fpopestimate2007_30_34
rename popestimate20078 Fpopestimate2007_35_39
rename popestimate20079 Fpopestimate2007_40_44
rename popestimate200710 Fpopestimate2007_45_49
rename popestimate200711 Fpopestimate2007_50_54
rename popestimate200712 Fpopestimate2007_55_59
rename popestimate200713 Fpopestimate2007_60_64
rename popestimate200714 Fpopestimate2007_65_69

//*Save Dataset*//
save Merge\F2007reducedcensusstate.dta , replace   
clear 

//*Male*//

//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 2

//*Create Variables for Each Age Group*//
keep agegrp popestimate2007 area_fips 
reshape wide popestimate2007 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20075 Mpopestimate2007_20_24
rename popestimate20076 Mpopestimate2007_25_29
rename popestimate20077 Mpopestimate2007_30_34
rename popestimate20078 Mpopestimate2007_35_39
rename popestimate20079 Mpopestimate2007_40_44
rename popestimate200710 Mpopestimate2007_45_49
rename popestimate200711 Mpopestimate2007_50_54
rename popestimate200712 Mpopestimate2007_55_59
rename popestimate200713 Mpopestimate2007_60_64
rename popestimate200714 Mpopestimate2007_65_69

//*Save Dataset*//
save Merge\M2007reducedcensusstate.dta , replace   
clear 

//*******************************2008*********************************//

//*Female*//
//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 1

//*Create Variables for Each Age Group*//
keep agegrp popestimate2008 area_fips 
reshape wide popestimate2008 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20085 Fpopestimate2008_20_24
rename popestimate20086 Fpopestimate2008_25_29
rename popestimate20087 Fpopestimate2008_30_34
rename popestimate20088 Fpopestimate2008_35_39
rename popestimate20089 Fpopestimate2008_40_44
rename popestimate200810 Fpopestimate2008_45_49
rename popestimate200811 Fpopestimate2008_50_54
rename popestimate200812 Fpopestimate2008_55_59
rename popestimate200813 Fpopestimate2008_60_64
rename popestimate200814 Fpopestimate2008_65_69

//*Save Dataset*//
save Merge\F2008reducedcensusstate.dta , replace   
clear 

//*Male*//
//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 2

//*Create Variables for Each Age Group*//
keep agegrp popestimate2008 area_fips 
reshape wide popestimate2008 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20085 Mpopestimate2008_20_24
rename popestimate20086 Mpopestimate2008_25_29
rename popestimate20087 Mpopestimate2008_30_34
rename popestimate20088 Mpopestimate2008_35_39
rename popestimate20089 Mpopestimate2008_40_44
rename popestimate200810 Mpopestimate2008_45_49
rename popestimate200811 Mpopestimate2008_50_54
rename popestimate200812 Mpopestimate2008_55_59
rename popestimate200813 Mpopestimate2008_60_64
rename popestimate200814 Mpopestimate2008_65_69

//*Save Dataset*//
save Merge\M2008reducedcensusstate.dta , replace   
clear 

//*******************************2009*********************************//

//*Female*//
//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 1

//*Create Variables for Each Age Group*//
keep agegrp popestimate2009 area_fips 
reshape wide popestimate2009 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20095 Fpopestimate2009_20_24
rename popestimate20096 Fpopestimate2009_25_29
rename popestimate20097 Fpopestimate2009_30_34
rename popestimate20098 Fpopestimate2009_35_39
rename popestimate20099 Fpopestimate2009_40_44
rename popestimate200910 Fpopestimate2009_45_49
rename popestimate200911 Fpopestimate2009_50_54
rename popestimate200912 Fpopestimate2009_55_59
rename popestimate200913 Fpopestimate2009_60_64
rename popestimate200914 Fpopestimate2009_65_69

//*Save Dataset*//
save Merge\F2009reducedcensusstate.dta , replace   
clear 

//*Male*//
//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 2

//*Create Variables for Each Age Group*//
keep agegrp popestimate2009 area_fips 
reshape wide popestimate2009 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20095 Mpopestimate2009_20_24
rename popestimate20096 Mpopestimate2009_25_29
rename popestimate20097 Mpopestimate2009_30_34
rename popestimate20098 Mpopestimate2009_35_39
rename popestimate20099 Mpopestimate2009_40_44
rename popestimate200910 Mpopestimate2009_45_49
rename popestimate200911 Mpopestimate2009_50_54
rename popestimate200912 Mpopestimate2009_55_59
rename popestimate200913 Mpopestimate2009_60_64
rename popestimate200914 Mpopestimate2009_65_69

//*Save Dataset*//
save Merge\M2009reducedcensusstate.dta , replace   
clear 

//*******************************2010*********************************//

//*Female*//
//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 1

//*Create Variables for Each Age Group*//
keep agegrp popestimate2010 area_fips 
reshape wide popestimate2010 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20105 Fpopestimate2010_20_24
rename popestimate20106 Fpopestimate2010_25_29
rename popestimate20107 Fpopestimate2010_30_34
rename popestimate20108 Fpopestimate2010_35_39
rename popestimate20109 Fpopestimate2010_40_44
rename popestimate201010 Fpopestimate2010_45_49
rename popestimate201011 Fpopestimate2010_50_54
rename popestimate201012 Fpopestimate2010_55_59
rename popestimate201013 Fpopestimate2010_60_64
rename popestimate201014 Fpopestimate2010_65_69

//*Save Dataset*//
save Merge\F2010reducedcensusstate.dta , replace   
clear 

//*Male*//
//*import Census importable file*// 
	use Importable\censusstate.dta 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop estimatesbase2000 popestimate2000 popestimate2001 popestimate2002 popestimate2003 popestimate2004 popestimate2005
drop if agegrp <= 4 
drop if agegrp >= 15
drop if origin == 1
drop if origin == 2
drop if race >=1
drop if sex == 0
drop if sex == 2

//*Create Variables for Each Age Group*//
keep agegrp popestimate2010 area_fips 
reshape wide popestimate2010 , i(area_fips) j(agegrp) 

//*Rename Variables*//
rename popestimate20105 Mpopestimate2010_20_24
rename popestimate20106 Mpopestimate2010_25_29
rename popestimate20107 Mpopestimate2010_30_34
rename popestimate20108 Mpopestimate2010_35_39
rename popestimate20109 Mpopestimate2010_40_44
rename popestimate201010 Mpopestimate2010_45_49
rename popestimate201011 Mpopestimate2010_50_54
rename popestimate201012 Mpopestimate2010_55_59
rename popestimate201013 Mpopestimate2010_60_64
rename popestimate201014 Mpopestimate2010_65_69

//*Save Dataset*//
save Merge\M2010reducedcensusstate.dta , replace   
clear 

//*******************************2011*********************************//

//*Female*//
//*import Census importable file*// 
	use Importable\censusstate2011 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop if age <= 19 
drop if age >= 70
drop if sex == 0
drop if sex == 1

//*Create Variables for Each Age Group*//
keep age popest2011_civ area_fips 
reshape wide popest2011_civ , i(area_fips) j(age) 

//*Combine Age Groups Into One Variable*//
egen Femalepop2011 = rowtotal(popest2011_civ20 popest2011_civ21 popest2011_civ22 popest2011_civ23 popest2011_civ24 popest2011_civ25 popest2011_civ26 popest2011_civ27 popest2011_civ28 popest2011_civ29 popest2011_civ30 popest2011_civ31 popest2011_civ32 popest2011_civ33 popest2011_civ34 popest2011_civ35 popest2011_civ36 popest2011_civ37 popest2011_civ38 popest2011_civ39 popest2011_civ40 popest2011_civ41 popest2011_civ42 popest2011_civ43 popest2011_civ44 popest2011_civ45 popest2011_civ46 popest2011_civ47 popest2011_civ48 popest2011_civ49 popest2011_civ50 popest2011_civ51 popest2011_civ52 popest2011_civ53 popest2011_civ54 popest2011_civ55 popest2011_civ56 popest2011_civ57 popest2011_civ58 popest2011_civ59 popest2011_civ60 popest2011_civ61 popest2011_civ62 popest2011_civ63 popest2011_civ64 popest2011_civ65 popest2011_civ66 popest2011_civ67 popest2011_civ68 popest2011_civ69) 

//*Keep Needed Variables For Merging*//
keep Femalepop2011 area_fips 

//*Save Dataset*//
save Merge\F2011reducedcensusstate.dta , replace   
clear 

//*Male*//
//*import Census importable file*// 
	use Importable\censusstate2011 

//*Drop Unneeded States*// 
drop if state <= 20
drop if (state >=22 & state <=38) 
drop if (state >=40 & state <=41) 
drop if (state >=44 & state <=53) 
drop if (state >=55) 

//*Generate Area_Fips*//
generate area_fips = subinstr(name, "Kentucky","21000",.) 
replace area_fips = subinstr(area_fips, "Ohio","39000",.) 
replace area_fips = subinstr(area_fips, "Pennsylvania","42000",.) 
replace area_fips = subinstr(area_fips, "West Virginia","54000",.) 
destring area_fips, replace 

//*Drop Unneeded Years Ages Gender Other Variables*//
drop if age <= 19 
drop if age >= 70
drop if sex == 0
drop if sex == 2

//*Create Variables for Each Age Group*//
keep age popest2011_civ area_fips 
reshape wide popest2011_civ , i(area_fips) j(age) 

//*Combine Age Groups Into One Variable*//
egen Malepop2011 = rowtotal(popest2011_civ20 popest2011_civ21 popest2011_civ22 popest2011_civ23 popest2011_civ24 popest2011_civ25 popest2011_civ26 popest2011_civ27 popest2011_civ28 popest2011_civ29 popest2011_civ30 popest2011_civ31 popest2011_civ32 popest2011_civ33 popest2011_civ34 popest2011_civ35 popest2011_civ36 popest2011_civ37 popest2011_civ38 popest2011_civ39 popest2011_civ40 popest2011_civ41 popest2011_civ42 popest2011_civ43 popest2011_civ44 popest2011_civ45 popest2011_civ46 popest2011_civ47 popest2011_civ48 popest2011_civ49 popest2011_civ50 popest2011_civ51 popest2011_civ52 popest2011_civ53 popest2011_civ54 popest2011_civ55 popest2011_civ56 popest2011_civ57 popest2011_civ58 popest2011_civ59 popest2011_civ60 popest2011_civ61 popest2011_civ62 popest2011_civ63 popest2011_civ64 popest2011_civ65 popest2011_civ66 popest2011_civ67 popest2011_civ68 popest2011_civ69) 

//*Keep Needed Variables For Merging*//
keep Malepop2011 area_fips 

//*Save Dataset*//
save Merge\M2011reducedcensusstate.dta , replace   
clear 


//*******************************************************************//


//***************************Merge Census*****************************//

//*Merging Reduced County Census Datasets Together*//
use Merge\F2006reducedcensus.dta 
	merge 1:1 area_fips using Merge\M2006reducedcensus.dta 
		rename _merge merge1
	merge 1:1 area_fips using Merge\F2007reducedcensus.dta
		rename _merge merge3 
	merge 1:1 area_fips using Merge\M2007reducedcensus.dta
		rename _merge merge4
	merge 1:1 area_fips using Merge\F2008reducedcensus.dta
		rename _merge merge6 
	merge 1:1 area_fips using Merge\M2008reducedcensus.dta
		rename _merge merge7
	merge 1:1 area_fips using Merge\F2009reducedcensus.dta
		rename _merge merge9 
	merge 1:1 area_fips using Merge\M2009reducedcensus.dta
		rename _merge merge10
	merge 1:1 area_fips using Merge\F2010reducedcensus.dta
		rename _merge merge12 
	merge 1:1 area_fips using Merge\M2010reducedcensus.dta
		rename _merge merge13
	merge 1:1 area_fips using Merge\F2011reducedcensus.dta
		rename _merge merge15
	merge 1:1 area_fips using Merge\M2011reducedcensus.dta
		rename _merge merge16
		
//*Save Merged County Data*//
save Merge\reducedcensus.dta , replace 
clear 

//*Merging Reduced State Census Datasets Together*//
use Merge\F2006reducedcensusstate.dta	
	merge 1:1 area_fips using Merge\M2006reducedcensusstate.dta 
		rename _merge merge15
	merge 1:1 area_fips using Merge\F2007reducedcensusstate.dta
		rename _merge merge17
	merge 1:1 area_fips using Merge\M2007reducedcensusstate.dta
		rename _merge merge18
	merge 1:1 area_fips using Merge\F2008reducedcensusstate.dta
		rename _merge merge20
	merge 1:1 area_fips using Merge\M2008reducedcensusstate.dta
		rename _merge merge21
	merge 1:1 area_fips using Merge\F2009reducedcensusstate.dta
		rename _merge merge23
	merge 1:1 area_fips using Merge\M2009reducedcensusstate.dta
		rename _merge merge24
	merge 1:1 area_fips using Merge\F2010reducedcensusstate.dta
		rename _merge merge26 
	merge 1:1 area_fips using Merge\M2010reducedcensusstate.dta
		rename _merge merge27
	merge 1:1 area_fips using Merge\M2011reducedcensusstate.dta
		rename _merge merge29
	merge 1:1 area_fips using Merge\F2011reducedcensusstate.dta
		rename _merge merge30 

//*Save Merged State Data*//
save Merge\reducedcensusstate.dta , replace 
clear 


//*******************************************************************//

//*import Mine Data importable file*// 
	use Importable\2006minedata.dta 

//*Recode State Variables*// 
generate minestate2 = subinstr(minestate, "Kentucky (East)","1",.)
replace minestate2 = subinstr(minestate2, "Kentucky (West)","1",.)  
replace minestate2 = subinstr(minestate2, "Ohio","2",.) 
replace minestate2 = subinstr(minestate2, "Pennsylvania (Bituminous)","3",.) 
replace minestate2 = subinstr(minestate2, "Pennsylvania (Anthracite)","3",.) 
replace minestate2 = subinstr(minestate2, "West Virginia (Northern)","4",.) 
replace minestate2 = subinstr(minestate2, "West Virginia (Southern)","4",.) 

destring minestate2, replace force 

//*Drop Unneeded States*// 
keep if (minestate2 >=1 & minestate2 <=7) 

//*Recode County Variables to FIPS*// 
generate area_fips = subinstr(minecounty, "Adair","21001",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Allen","21003",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Anderson","21005",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Ballard","21007",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Barren","21009",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Bath","21011",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Bell","21013",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Boone","21015",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Bourbon","21017",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Boyd","21019",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Boyle","21021",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Bracken","21023",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Breathitt","21025",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Breckinridge","21027",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Bullitt","21029",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Butler","21031",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Caldwell","21033",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Calloway","21035",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Campbell","21037",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Carlisle","21039",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Carroll","21041",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Carter","21043",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Casey","21045",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Christian","21047",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Clark","21049",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Clay","21051",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Clinton","21053",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Crittenden","21055",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Cumberland","21057",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Daviess","21059",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Edmonson","21061",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Elliott","21063",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Estill","21065",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Fayette","21067",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Fleming","21069",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Floyd","21071",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Franklin","21073",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Fulton","21075",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Gallatin","21077",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Garrard","21079",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Grant","21081",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Graves","21083",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Grayson","21085",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Green","21087",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Greenup","21089",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Hancock","21091",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Hardin","21093",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Harlan","21095",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Harrison","21097",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Hart","21099",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Henderson","21101",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Henry","21103",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Hickman","21105",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Hopkins","21107",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Jackson","21109",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Jefferson","21111",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Jessamine","21113",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Johnson","21115",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Kenton","21117",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Knott","21119",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Knox","21121",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Larue","21123",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Laurel","21125",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Lawrence","21127",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Lee","21129",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Leslie","21131",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Letcher","21133",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Lewis","21135",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Lincoln","21137",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Livingston","21139",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Logan","21141",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Lyon","21143",.) if minestate2==1
replace area_fips = subinstr(area_fips, "McCracken","21145",.) if minestate2==1
replace area_fips = subinstr(area_fips, "McCreary","21147",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Mclean","21149",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Madison","21151",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Magoffin","21153",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Marion","21155",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Marshall","21157",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Martin","21159",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Mason","21161",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Meade","21163",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Menifee","21165",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Mercer","21167",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Metcalfe","21169",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Monroe","21171",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Montgomery","21173",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Morgan","21175",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Muhlenberg","21177",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Nelson","21179",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Nicholas","21181",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Ohio","21183",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Oldham","21185",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Owen","21187",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Owsley","21189",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Pendleton","21191",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Perry","21193",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Pike","21195",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Powell","21197",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Pulaski","21199",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Robertson","21201",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Rockcastle","21203",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Rowan","21205",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Russell","21207",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Scott","21209",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Shelby","21211",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Simpson","21213",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Spencer","21215",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Taylor","21217",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Todd","21219",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Trigg","21221",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Trimble","21223",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Union","21225",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Warren","21227",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Washington","21229",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Wayne","21231",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Webster","21233",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Whitley","21235",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Wolfe","21237",.) if minestate2==1
replace area_fips = subinstr(area_fips, "Woodford","21239",.) if minestate2==1
replace area_fips = subinstr(minecounty, "Adams","39001",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Allen","39003",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Ashland","39005",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Ashtabula","39007",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Athans","39009",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Auglaize","39011",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Belmont","39013",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Brown","39015",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Butler","39017",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Carroll","39019",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Champaign","39021",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Clark","39023",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Clermont","39025",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Clinton","39027",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Columbiana","39029",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Coshocton","39031",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Crawford","39033",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Cuyahoga","39035",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Darke","39037",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Defiance","39039",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Delaware","39041",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Erie","39043",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Fairfield","39045",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Fayette","39047",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Franklin","39049",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Fulton","39051",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Gallia","39053",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Geauga","39055",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Greene","39057",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Guernsey","39059",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Hamilton","39061",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Hancock","39063",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Hardin","39065",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Harrison","39067",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Henry","39069",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Highland","39071",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Hocking","39073",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Holmes","39075",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Huron","39077",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Jackson","39079",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Jefferson","39081",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Knox","39083",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Lake","39085",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Lawrence","39087",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Licking","39089",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Logan","39091",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Lorain","39093",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Lucas","39095",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Madison","39097",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Mahoning","39099",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Marion","39101",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Medina","39103",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Meigs","39105",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Mercer","39107",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Miami","39109",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Monroe","39111",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Montgomery","39113",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Morgan","39115",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Morrow","39117",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Muskingum","39119",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Noble","39121",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Ottawa","39123",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Paulding","39125",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Perry","39127",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Pickaway","39129",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Pike","39131",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Portage","39133",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Preble","39135",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Putnam","39137",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Richland","39139",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Ross","39141",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Sandusky","39143",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Scioto","39145",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Seneca","39147",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Shelby","39149",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Stark","39151",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Summit","39153",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Trumbull","39155",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Tuscarawas","39157",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Union","39159",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Van Wert","39161",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Vinton","39163",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Warren","39165",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Washington","39167",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Wayne","39169",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Williams","39171",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Wood","39173",.) if minestate2==2
replace area_fips = subinstr(area_fips, "Wyandot","39175",.) if minestate2==2
replace area_fips = subinstr(minecounty, "Adams","42001",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Allegheny","42003",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Armstrong","42005",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Beaver","42007",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Bedford","42009",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Berks","42011",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Blair","42013",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Bradford","42015",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Bucks","42017",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Butler","42019",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Cambria","42021",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Cameron","42023",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Carbon","42025",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Centre","42027",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Chester","42029",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Clarion","42031",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Clearfield","42033",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Clinton","42035",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Columbia","42037",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Crawford","42039",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Cumberland","42041",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Dauphin","42043",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Delaware","42045",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Elk","42047",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Erie","42049",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Fayette","42051",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Forest","42053",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Franklin","42055",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Fulton","42057",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Greene","42059",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Huntingdon","42061",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Indiana","42063",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Jefferson","42065",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Juniata","42067",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Lackawanna","42069",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Lancaster","42071",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Lawrence","42073",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Lebanon","42075",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Lehigh","42077",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Luzerne","42079",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Lycoming","42081",.) if minestate2==3
replace area_fips = subinstr(area_fips, "McKean","42083",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Mercer","42085",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Mifflin","42087",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Monroe","42089",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Montgomery","42091",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Montour","42093",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Northampton","42095",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Northumberland","42097",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Perry","42099",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Philadelphia","42101",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Pike","42103",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Potter","42105",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Schuylkill","42107",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Snyder","42109",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Somerset","42111",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Sullivan","42113",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Susquehanna","42115",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Tioga","42117",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Union","42119",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Venango","42121",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Warren","42123",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Washington","42125",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Wayne","42127",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Westmoreland","42129",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Wyoming","42131",.) if minestate2==3
replace area_fips = subinstr(area_fips, "York","42133",.) if minestate2==3
replace area_fips = subinstr(minecounty, "Barbour","54001",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Berkeley","54003",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Boone","54005",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Braxton","54007",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Brooke","54009",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Cabell","54011",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Calhoun","54013",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Clay","54015",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Doddridge","54017",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Fayette","54019",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Gilmer","54021",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Grant","54023",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Greenbrier","54025",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Hampshire","54027",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Hancock","54029",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Hardy","54031",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Harrison","54033",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Jackson","54035",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Jefferson","54037",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Kanawha","54039",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Lewis","54041",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Lincoln","54043",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Logan","54045",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Mcdowell","54047",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Marion","54049",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Marshall","54051",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Mason","54053",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Mercer","54055",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Mineral","54057",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Mingo","54059",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Monongalia","54061",.) if minestate2==3
replace area_fips = subinstr(area_fips, "Monongalia","54061",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Monroe","54063",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Morgan","54065",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Nicholas","54067",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Ohio","54069",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Pendleton","54071",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Pleasants","54073",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Pocahontas","54075",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Preston","54077",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Putnam","54079",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Raleigh","54081",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Randolph","54083",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Ritchie","54085",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Roane","54087",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Summers","54089",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Taylor","54091",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Tucker","54093",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Tyler","54095",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Upshur","54097",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Wayne","54099",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Webster","54101",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Wetzel","54103",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Wirt","54105",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Wood","54107",.) if minestate2==4
replace area_fips = subinstr(area_fips, "Wyoming","54109",.) if minestate2==4

//*Destring FIPS*// 
destring area_fips , replace 

//*Fix Error in Data*// 
replace minestate2 = 4 if area_fips == 54061

//*Count Mines per County*// 
contract area_fips, freq(minecount) 

//*Save Dataset*// 
save Merge\reducedminecount.dta, replace  
clear 

//*******************************************************************//
//************************Employement Datasets***********************//
//*******************************************************************//

//*******************************************************************//
//********************************2006*******************************//
//*******************************************************************//

//*import 2006 all industries datafile*// 
	use Importable\2006allindustries.dta  

//*Drop Unneeded States*// 
drop if agglvl_code <=41
drop if agglvl_code >=80 & agglvl_code <=95
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename disclosure_code allindustriesdisclosurecode	 
rename qtrly_estabs_count allindustriesestablishments	
rename month1_emplvl allindustriesemploymentmo1	
rename month2_emplvl allindustriesemploymentmo2	
rename month3_emplvl allindustriesemploymentmo3
rename total_qtrly_wages allindustriestotalwages	
rename taxable_qtrly_wages allindustriestaxablewages
rename qtrly_contributions allindustriesqrtcontributions
rename avg_wkly_wage allindustriesavgwklywage
rename lq_disclosure_code allindustrieslqdisclosurecode	
rename lq_qtrly_estabs_count allindustrieslqempqrtly	
rename lq_month1_emplvl allindustrieslqempmo1
rename lq_month2_emplvl allindustrieslqempmo2
rename lq_month3_emplvl allindustrieslqempmo3
rename lq_total_qtrly_wages allindustrieslqwageqrtly
rename lq_taxable_qtrly_wages allindustrieslqtaxwageqrtly
rename lq_qtrly_contributions allindustriescontriqrtly	
rename lq_avg_wkly_wage allindustriesavgwkwageqrtly

//*Drop Unneeded Observations*//
generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

//*Save Dataset*//
save Merge\reduced2006allindustries.dta , replace 
clear 

//*******************************************************************//

//*import 2006 Coal Mining  datafile*// 
	use Importable\2006coal.dta 
	
//*Drop Unneeded States*// 
drop if agglvl_code == 46
drop if agglvl_code == 16
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*// 
rename qtrly_estabs_count coalestablishments	
rename month1_emplvl coalemploymentmo1	
rename month2_emplvl coalemploymentmo2	
rename month3_emplvl coalemploymentmo3
rename total_qtrly_wages coaltotalwages	
rename taxable_qtrly_wages coaltaxablewages
rename qtrly_contributions coalqrtcontributions
rename avg_wkly_wage coalavgwklywage
rename lq_disclosure_code coaldisclosurecode	
rename lq_qtrly_estabs_count coallqempqrtly	
rename lq_month1_emplvl	coallqempmo1
rename lq_month2_emplvl	coallqempmo2
rename lq_month3_emplvl	coallqempmo3
rename lq_total_qtrly_wages coallqwageqrtly
rename lq_taxable_qtrly_wages coallqtaxwageqrtly
rename lq_qtrly_contributions coalcontriqrtly	
rename lq_avg_wkly_wage coalavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 

//*Save Dataset*//
save Merge\reduced2006coalmining.dta , replace 
clear 

//*******************************************************************//

//*import 2006 Construction datafile*// 
	use Importable\2006construction.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count constructionestablishments	
rename month1_emplvl constructionemploymentmo1	
rename month2_emplvl constructionemploymentmo2	
rename month3_emplvl constructionemploymentmo3
rename total_qtrly_wages constructiontotalwages	
rename taxable_qtrly_wages constructiontaxablewages
rename qtrly_contributions constructionqrtcontributions
rename avg_wkly_wage constructionavgwklywage
rename lq_disclosure_code constructiondisclosurecode	
rename lq_qtrly_estabs_count constructionlqempqrtly	
rename lq_month1_emplvl constructionlqempmo1
rename lq_month2_emplvl constructionlqempmo2
rename lq_month3_emplvl constructionlqempmo3
rename lq_total_qtrly_wages constructionlqwageqrtly
rename lq_taxable_qtrly_wages constructionlqtaxwageqrtly
rename lq_qtrly_contributions constructioncontriqrtly	
rename lq_avg_wkly_wage constructionavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2006construction.dta , replace 
clear 

//*******************************************************************//

//*import 2006 Manufacturing datafile*// 
	use Importable\2006manufacturing.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count manufacturingestablishments	
rename month1_emplvl manufacturingemploymentmo1	
rename month2_emplvl manufacturingemploymentmo2	
rename month3_emplvl manufacturingemploymentmo3
rename total_qtrly_wages manufacturingtotalwages	
rename taxable_qtrly_wages manufacturingtaxablewages
rename qtrly_contributions manufacturingqrtcontributions
rename avg_wkly_wage manufacturingavgwklywage
rename lq_disclosure_code manufacturingdisclosurecode	
rename lq_qtrly_estabs_count manufacturinglqempqrtly	
rename lq_month1_emplvl manufacturinglqempmo1
rename lq_month2_emplvl manufacturinglqempmo2
rename lq_month3_emplvl manufacturinglqempmo3
rename lq_total_qtrly_wages manufacturinglqwageqrtly
rename lq_taxable_qtrly_wages manufacturinglqtaxwageqrtly
rename lq_qtrly_contributions manufacturingcontriqrtly	
rename lq_avg_wkly_wage manufacturingavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2006manufacturing.dta , replace 
clear 

//*******************************************************************//

//*import 2006 Retail Trade datafile*// 
	use Importable\2006retailtrade.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count retailtradeestablishments	
rename month1_emplvl retailtradeemploymentmo1	
rename month2_emplvl retailtradeemploymentmo2	
rename month3_emplvl retailtradeemploymentmo3
rename total_qtrly_wages retailtradetotalwages	
rename taxable_qtrly_wages retailtradetaxablewages
rename qtrly_contributions retailtradeqrtcontributions
rename avg_wkly_wage retailtradeavgwklywage
rename lq_disclosure_code retailtradedisclosurecode	
rename lq_qtrly_estabs_count retailtradelqempqrtly	
rename lq_month1_emplvl retailtradelqempmo1
rename lq_month2_emplvl retailtradelqempmo2
rename lq_month3_emplvl retailtradelqempmo3
rename lq_total_qtrly_wages retailtradelqwageqrtly
rename lq_taxable_qtrly_wages retailtradelqtaxwageqrtly
rename lq_qtrly_contributions retailtradecontriqrtly	
rename lq_avg_wkly_wage retailtradeavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2006retailtrade.dta , replace 
clear 

//*******************************************************************//

//*import 2006 Service Providing datafile*// 
	use Importable\2006service.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 42
drop if agglvl_code == 12
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count serviceestablishments	
rename month1_emplvl serviceemploymentmo1	
rename month2_emplvl serviceemploymentmo2	
rename month3_emplvl serviceemploymentmo3
rename total_qtrly_wages servicetotalwages	
rename taxable_qtrly_wages servicetaxablewages
rename qtrly_contributions serviceqrtcontributions
rename avg_wkly_wage serviceavgwklywage
rename lq_disclosure_code servicedisclosurecode	
rename lq_qtrly_estabs_count servicelqempqrtly	
rename lq_month1_emplvl servicelqempmo1
rename lq_month2_emplvl servicelqempmo2
rename lq_month3_emplvl servicelqempmo3
rename lq_total_qtrly_wages servicelqwageqrtly
rename lq_taxable_qtrly_wages servicelqtaxwageqrtly
rename lq_qtrly_contributions servicecontriqrtly	
rename lq_avg_wkly_wage serviceavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2006service.dta , replace 
clear 

//*******************************************************************//
//********************************2007*******************************//
//*******************************************************************//

//*import 2007 all industries datafile*// 
	use Importable\2007allindustries.dta  

//*Drop Unneeded States*// 
drop if agglvl_code <=41
drop if agglvl_code >=80 & agglvl_code <=95
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename disclosure_code allindustriesdisclosurecode	 
rename qtrly_estabs_count allindustriesestablishments	
rename month1_emplvl allindustriesemploymentmo1	
rename month2_emplvl allindustriesemploymentmo2	
rename month3_emplvl allindustriesemploymentmo3
rename total_qtrly_wages allindustriestotalwages	
rename taxable_qtrly_wages allindustriestaxablewages
rename qtrly_contributions allindustriesqrtcontributions
rename avg_wkly_wage allindustriesavgwklywage
rename lq_disclosure_code allindustrieslqdisclosurecode	
rename lq_qtrly_estabs_count allindustrieslqempqrtly	
rename lq_month1_emplvl allindustrieslqempmo1
rename lq_month2_emplvl allindustrieslqempmo2
rename lq_month3_emplvl allindustrieslqempmo3
rename lq_total_qtrly_wages allindustrieslqwageqrtly
rename lq_taxable_qtrly_wages allindustrieslqtaxwageqrtly
rename lq_qtrly_contributions allindustriescontriqrtly	
rename lq_avg_wkly_wage allindustriesavgwkwageqrtly

//*Drop Unneeded Observations*//
generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

//*Save Dataset*//
save Merge\reduced2007allindustries.dta , replace 
clear 

//*******************************************************************//

//*import 2007 Coal Mining  datafile*// 
	use Importable\2007coal.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 46
drop if agglvl_code == 16
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*// 
rename qtrly_estabs_count coalestablishments	
rename month1_emplvl coalemploymentmo1	
rename month2_emplvl coalemploymentmo2	
rename month3_emplvl coalemploymentmo3
rename total_qtrly_wages coaltotalwages	
rename taxable_qtrly_wages coaltaxablewages
rename qtrly_contributions coalqrtcontributions
rename avg_wkly_wage coalavgwklywage
rename lq_disclosure_code coaldisclosurecode	
rename lq_qtrly_estabs_count coallqempqrtly	
rename lq_month1_emplvl	coallqempmo1
rename lq_month2_emplvl	coallqempmo2
rename lq_month3_emplvl	coallqempmo3
rename lq_total_qtrly_wages coallqwageqrtly
rename lq_taxable_qtrly_wages coallqtaxwageqrtly
rename lq_qtrly_contributions coalcontriqrtly	
rename lq_avg_wkly_wage coalavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 

//*Save Dataset*//
save Merge\reduced2007coalmining.dta , replace 
clear 

//*******************************************************************//

//*import 2007 Construction datafile*// 
	use Importable\2007construction.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count constructionestablishments	
rename month1_emplvl constructionemploymentmo1	
rename month2_emplvl constructionemploymentmo2	
rename month3_emplvl constructionemploymentmo3
rename total_qtrly_wages constructiontotalwages	
rename taxable_qtrly_wages constructiontaxablewages
rename qtrly_contributions constructionqrtcontributions
rename avg_wkly_wage constructionavgwklywage
rename lq_disclosure_code constructiondisclosurecode	
rename lq_qtrly_estabs_count constructionlqempqrtly	
rename lq_month1_emplvl constructionlqempmo1
rename lq_month2_emplvl constructionlqempmo2
rename lq_month3_emplvl constructionlqempmo3
rename lq_total_qtrly_wages constructionlqwageqrtly
rename lq_taxable_qtrly_wages constructionlqtaxwageqrtly
rename lq_qtrly_contributions constructioncontriqrtly	
rename lq_avg_wkly_wage constructionavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2007construction.dta , replace 
clear 

//*******************************************************************//

//*import 2007 Manufacturing datafile*// 
	use Importable\2007manufacturing.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count manufacturingestablishments	
rename month1_emplvl manufacturingemploymentmo1	
rename month2_emplvl manufacturingemploymentmo2	
rename month3_emplvl manufacturingemploymentmo3
rename total_qtrly_wages manufacturingtotalwages	
rename taxable_qtrly_wages manufacturingtaxablewages
rename qtrly_contributions manufacturingqrtcontributions
rename avg_wkly_wage manufacturingavgwklywage
rename lq_disclosure_code manufacturingdisclosurecode	
rename lq_qtrly_estabs_count manufacturinglqempqrtly	
rename lq_month1_emplvl manufacturinglqempmo1
rename lq_month2_emplvl manufacturinglqempmo2
rename lq_month3_emplvl manufacturinglqempmo3
rename lq_total_qtrly_wages manufacturinglqwageqrtly
rename lq_taxable_qtrly_wages manufacturinglqtaxwageqrtly
rename lq_qtrly_contributions manufacturingcontriqrtly	
rename lq_avg_wkly_wage manufacturingavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2007manufacturing.dta , replace 
clear 

//*******************************************************************//

//*import 2007 Retail Trade datafile*// 
	use Importable\2007retailtrade.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count retailtradeestablishments	
rename month1_emplvl retailtradeemploymentmo1	
rename month2_emplvl retailtradeemploymentmo2	
rename month3_emplvl retailtradeemploymentmo3
rename total_qtrly_wages retailtradetotalwages	
rename taxable_qtrly_wages retailtradetaxablewages
rename qtrly_contributions retailtradeqrtcontributions
rename avg_wkly_wage retailtradeavgwklywage
rename lq_disclosure_code retailtradedisclosurecode	
rename lq_qtrly_estabs_count retailtradelqempqrtly	
rename lq_month1_emplvl retailtradelqempmo1
rename lq_month2_emplvl retailtradelqempmo2
rename lq_month3_emplvl retailtradelqempmo3
rename lq_total_qtrly_wages retailtradelqwageqrtly
rename lq_taxable_qtrly_wages retailtradelqtaxwageqrtly
rename lq_qtrly_contributions retailtradecontriqrtly	
rename lq_avg_wkly_wage retailtradeavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2007retailtrade.dta , replace 
clear 

//*******************************************************************//

//*import 2007 Service Providing datafile*// 
	use Importable\2007service.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 42
drop if agglvl_code == 12
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count serviceestablishments	
rename month1_emplvl serviceemploymentmo1	
rename month2_emplvl serviceemploymentmo2	
rename month3_emplvl serviceemploymentmo3
rename total_qtrly_wages servicetotalwages	
rename taxable_qtrly_wages servicetaxablewages
rename qtrly_contributions serviceqrtcontributions
rename avg_wkly_wage serviceavgwklywage
rename lq_disclosure_code servicedisclosurecode	
rename lq_qtrly_estabs_count servicelqempqrtly	
rename lq_month1_emplvl servicelqempmo1
rename lq_month2_emplvl servicelqempmo2
rename lq_month3_emplvl servicelqempmo3
rename lq_total_qtrly_wages servicelqwageqrtly
rename lq_taxable_qtrly_wages servicelqtaxwageqrtly
rename lq_qtrly_contributions servicecontriqrtly	
rename lq_avg_wkly_wage serviceavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2007service.dta , replace 
clear 

//*******************************************************************//
//********************************2008*******************************//
//*******************************************************************//

//*import 2008 all industries datafile*// 
	use Importable\2008allindustries.dta  

//*Drop Unneeded States*// 
drop if agglvl_code <=41
drop if agglvl_code >=80 & agglvl_code <=95
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename disclosure_code allindustriesdisclosurecode	 
rename qtrly_estabs_count allindustriesestablishments	
rename month1_emplvl allindustriesemploymentmo1	
rename month2_emplvl allindustriesemploymentmo2	
rename month3_emplvl allindustriesemploymentmo3
rename total_qtrly_wages allindustriestotalwages	
rename taxable_qtrly_wages allindustriestaxablewages
rename qtrly_contributions allindustriesqrtcontributions
rename avg_wkly_wage allindustriesavgwklywage
rename lq_disclosure_code allindustrieslqdisclosurecode	
rename lq_qtrly_estabs_count allindustrieslqempqrtly	
rename lq_month1_emplvl allindustrieslqempmo1
rename lq_month2_emplvl allindustrieslqempmo2
rename lq_month3_emplvl allindustrieslqempmo3
rename lq_total_qtrly_wages allindustrieslqwageqrtly
rename lq_taxable_qtrly_wages allindustrieslqtaxwageqrtly
rename lq_qtrly_contributions allindustriescontriqrtly	
rename lq_avg_wkly_wage allindustriesavgwkwageqrtly

//*Drop Unneeded Observations*//
generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

//*Save Dataset*//
save Merge\reduced2008allindustries.dta , replace 
clear 

//*******************************************************************//

//*import 2008 Coal Mining  datafile*// 
	use Importable\2008coal.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 46
drop if agglvl_code == 16
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*// 
rename qtrly_estabs_count coalestablishments	
rename month1_emplvl coalemploymentmo1	
rename month2_emplvl coalemploymentmo2	
rename month3_emplvl coalemploymentmo3
rename total_qtrly_wages coaltotalwages	
rename taxable_qtrly_wages coaltaxablewages
rename qtrly_contributions coalqrtcontributions
rename avg_wkly_wage coalavgwklywage
rename lq_disclosure_code coaldisclosurecode	
rename lq_qtrly_estabs_count coallqempqrtly	
rename lq_month1_emplvl	coallqempmo1
rename lq_month2_emplvl	coallqempmo2
rename lq_month3_emplvl	coallqempmo3
rename lq_total_qtrly_wages coallqwageqrtly
rename lq_taxable_qtrly_wages coallqtaxwageqrtly
rename lq_qtrly_contributions coalcontriqrtly	
rename lq_avg_wkly_wage coalavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 

//*Save Dataset*//
save Merge\reduced2008coalmining.dta , replace 
clear 

//*******************************************************************//

//*import 2008 Construction datafile*// 
	use Importable\2008construction.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count constructionestablishments	
rename month1_emplvl constructionemploymentmo1	
rename month2_emplvl constructionemploymentmo2	
rename month3_emplvl constructionemploymentmo3
rename total_qtrly_wages constructiontotalwages	
rename taxable_qtrly_wages constructiontaxablewages
rename qtrly_contributions constructionqrtcontributions
rename avg_wkly_wage constructionavgwklywage
rename lq_disclosure_code constructiondisclosurecode	
rename lq_qtrly_estabs_count constructionlqempqrtly	
rename lq_month1_emplvl constructionlqempmo1
rename lq_month2_emplvl constructionlqempmo2
rename lq_month3_emplvl constructionlqempmo3
rename lq_total_qtrly_wages constructionlqwageqrtly
rename lq_taxable_qtrly_wages constructionlqtaxwageqrtly
rename lq_qtrly_contributions constructioncontriqrtly	
rename lq_avg_wkly_wage constructionavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2008construction.dta , replace 
clear 

//*******************************************************************//

//*import 2008 Manufacturing datafile*// 
	use Importable\2008manufacturing.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count manufacturingestablishments	
rename month1_emplvl manufacturingemploymentmo1	
rename month2_emplvl manufacturingemploymentmo2	
rename month3_emplvl manufacturingemploymentmo3
rename total_qtrly_wages manufacturingtotalwages	
rename taxable_qtrly_wages manufacturingtaxablewages
rename qtrly_contributions manufacturingqrtcontributions
rename avg_wkly_wage manufacturingavgwklywage
rename lq_disclosure_code manufacturingdisclosurecode	
rename lq_qtrly_estabs_count manufacturinglqempqrtly	
rename lq_month1_emplvl manufacturinglqempmo1
rename lq_month2_emplvl manufacturinglqempmo2
rename lq_month3_emplvl manufacturinglqempmo3
rename lq_total_qtrly_wages manufacturinglqwageqrtly
rename lq_taxable_qtrly_wages manufacturinglqtaxwageqrtly
rename lq_qtrly_contributions manufacturingcontriqrtly	
rename lq_avg_wkly_wage manufacturingavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2008manufacturing.dta , replace 
clear 

//*******************************************************************//

//*import 2008 Retail Trade datafile*// 
	use Importable\2008retailtrade.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count retailtradeestablishments	
rename month1_emplvl retailtradeemploymentmo1	
rename month2_emplvl retailtradeemploymentmo2	
rename month3_emplvl retailtradeemploymentmo3
rename total_qtrly_wages retailtradetotalwages	
rename taxable_qtrly_wages retailtradetaxablewages
rename qtrly_contributions retailtradeqrtcontributions
rename avg_wkly_wage retailtradeavgwklywage
rename lq_disclosure_code retailtradedisclosurecode	
rename lq_qtrly_estabs_count retailtradelqempqrtly	
rename lq_month1_emplvl retailtradelqempmo1
rename lq_month2_emplvl retailtradelqempmo2
rename lq_month3_emplvl retailtradelqempmo3
rename lq_total_qtrly_wages retailtradelqwageqrtly
rename lq_taxable_qtrly_wages retailtradelqtaxwageqrtly
rename lq_qtrly_contributions retailtradecontriqrtly	
rename lq_avg_wkly_wage retailtradeavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2008retailtrade.dta , replace 
clear 

//*******************************************************************//

//*import 2008 Service Providing datafile*// 
	use Importable\2008service.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 42
drop if agglvl_code == 12
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count serviceestablishments	
rename month1_emplvl serviceemploymentmo1	
rename month2_emplvl serviceemploymentmo2	
rename month3_emplvl serviceemploymentmo3
rename total_qtrly_wages servicetotalwages	
rename taxable_qtrly_wages servicetaxablewages
rename qtrly_contributions serviceqrtcontributions
rename avg_wkly_wage serviceavgwklywage
rename lq_disclosure_code servicedisclosurecode	
rename lq_qtrly_estabs_count servicelqempqrtly	
rename lq_month1_emplvl servicelqempmo1
rename lq_month2_emplvl servicelqempmo2
rename lq_month3_emplvl servicelqempmo3
rename lq_total_qtrly_wages servicelqwageqrtly
rename lq_taxable_qtrly_wages servicelqtaxwageqrtly
rename lq_qtrly_contributions servicecontriqrtly	
rename lq_avg_wkly_wage serviceavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2008service.dta , replace 
clear 

//*******************************************************************//
//********************************2009*******************************//
//*******************************************************************//

//*import 2009 all industries datafile*// 
	use Importable\2009allindustries.dta  

//*Drop Unneeded States*// 
drop if agglvl_code <=41
drop if agglvl_code >=80 & agglvl_code <=95
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename disclosure_code allindustriesdisclosurecode	 
rename qtrly_estabs_count allindustriesestablishments	
rename month1_emplvl allindustriesemploymentmo1	
rename month2_emplvl allindustriesemploymentmo2	
rename month3_emplvl allindustriesemploymentmo3
rename total_qtrly_wages allindustriestotalwages	
rename taxable_qtrly_wages allindustriestaxablewages
rename qtrly_contributions allindustriesqrtcontributions
rename avg_wkly_wage allindustriesavgwklywage
rename lq_disclosure_code allindustrieslqdisclosurecode	
rename lq_qtrly_estabs_count allindustrieslqempqrtly	
rename lq_month1_emplvl allindustrieslqempmo1
rename lq_month2_emplvl allindustrieslqempmo2
rename lq_month3_emplvl allindustrieslqempmo3
rename lq_total_qtrly_wages allindustrieslqwageqrtly
rename lq_taxable_qtrly_wages allindustrieslqtaxwageqrtly
rename lq_qtrly_contributions allindustriescontriqrtly	
rename lq_avg_wkly_wage allindustriesavgwkwageqrtly

//*Drop Unneeded Observations*//
generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

//*Save Dataset*//
save Merge\reduced2009allindustries.dta , replace 
clear 

//*******************************************************************//

//*import 2009 Coal Mining  datafile*// 
	use Importable\2009coal.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 46
drop if agglvl_code == 16
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*// 
rename qtrly_estabs_count coalestablishments	
rename month1_emplvl coalemploymentmo1	
rename month2_emplvl coalemploymentmo2	
rename month3_emplvl coalemploymentmo3
rename total_qtrly_wages coaltotalwages	
rename taxable_qtrly_wages coaltaxablewages
rename qtrly_contributions coalqrtcontributions
rename avg_wkly_wage coalavgwklywage
rename lq_disclosure_code coaldisclosurecode	
rename lq_qtrly_estabs_count coallqempqrtly	
rename lq_month1_emplvl	coallqempmo1
rename lq_month2_emplvl	coallqempmo2
rename lq_month3_emplvl	coallqempmo3
rename lq_total_qtrly_wages coallqwageqrtly
rename lq_taxable_qtrly_wages coallqtaxwageqrtly
rename lq_qtrly_contributions coalcontriqrtly	
rename lq_avg_wkly_wage coalavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 

//*Save Dataset*//
save Merge\reduced2009coalmining.dta , replace 
clear 

//*******************************************************************//

//*import 2009 Construction datafile*// 
	use Importable\2009construction.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count constructionestablishments	
rename month1_emplvl constructionemploymentmo1	
rename month2_emplvl constructionemploymentmo2	
rename month3_emplvl constructionemploymentmo3
rename total_qtrly_wages constructiontotalwages	
rename taxable_qtrly_wages constructiontaxablewages
rename qtrly_contributions constructionqrtcontributions
rename avg_wkly_wage constructionavgwklywage
rename lq_disclosure_code constructiondisclosurecode	
rename lq_qtrly_estabs_count constructionlqempqrtly	
rename lq_month1_emplvl constructionlqempmo1
rename lq_month2_emplvl constructionlqempmo2
rename lq_month3_emplvl constructionlqempmo3
rename lq_total_qtrly_wages constructionlqwageqrtly
rename lq_taxable_qtrly_wages constructionlqtaxwageqrtly
rename lq_qtrly_contributions constructioncontriqrtly	
rename lq_avg_wkly_wage constructionavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2009construction.dta , replace 
clear 

//*******************************************************************//

//*import 2009 Manufacturing datafile*// 
	use Importable\2009manufacturing.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count manufacturingestablishments	
rename month1_emplvl manufacturingemploymentmo1	
rename month2_emplvl manufacturingemploymentmo2	
rename month3_emplvl manufacturingemploymentmo3
rename total_qtrly_wages manufacturingtotalwages	
rename taxable_qtrly_wages manufacturingtaxablewages
rename qtrly_contributions manufacturingqrtcontributions
rename avg_wkly_wage manufacturingavgwklywage
rename lq_disclosure_code manufacturingdisclosurecode	
rename lq_qtrly_estabs_count manufacturinglqempqrtly	
rename lq_month1_emplvl manufacturinglqempmo1
rename lq_month2_emplvl manufacturinglqempmo2
rename lq_month3_emplvl manufacturinglqempmo3
rename lq_total_qtrly_wages manufacturinglqwageqrtly
rename lq_taxable_qtrly_wages manufacturinglqtaxwageqrtly
rename lq_qtrly_contributions manufacturingcontriqrtly	
rename lq_avg_wkly_wage manufacturingavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2009manufacturing.dta , replace 
clear 

//*******************************************************************//

//*import 2009 Retail Trade datafile*// 
	use Importable\2009retailtrade.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count retailtradeestablishments	
rename month1_emplvl retailtradeemploymentmo1	
rename month2_emplvl retailtradeemploymentmo2	
rename month3_emplvl retailtradeemploymentmo3
rename total_qtrly_wages retailtradetotalwages	
rename taxable_qtrly_wages retailtradetaxablewages
rename qtrly_contributions retailtradeqrtcontributions
rename avg_wkly_wage retailtradeavgwklywage
rename lq_disclosure_code retailtradedisclosurecode	
rename lq_qtrly_estabs_count retailtradelqempqrtly	
rename lq_month1_emplvl retailtradelqempmo1
rename lq_month2_emplvl retailtradelqempmo2
rename lq_month3_emplvl retailtradelqempmo3
rename lq_total_qtrly_wages retailtradelqwageqrtly
rename lq_taxable_qtrly_wages retailtradelqtaxwageqrtly
rename lq_qtrly_contributions retailtradecontriqrtly	
rename lq_avg_wkly_wage retailtradeavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2009retailtrade.dta , replace 
clear 

//*******************************************************************//

//*import 2009 Service Providing datafile*// 
	use Importable\2009service.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 42
drop if agglvl_code == 12
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count serviceestablishments	
rename month1_emplvl serviceemploymentmo1	
rename month2_emplvl serviceemploymentmo2	
rename month3_emplvl serviceemploymentmo3
rename total_qtrly_wages servicetotalwages	
rename taxable_qtrly_wages servicetaxablewages
rename qtrly_contributions serviceqrtcontributions
rename avg_wkly_wage serviceavgwklywage
rename lq_disclosure_code servicedisclosurecode	
rename lq_qtrly_estabs_count servicelqempqrtly	
rename lq_month1_emplvl servicelqempmo1
rename lq_month2_emplvl servicelqempmo2
rename lq_month3_emplvl servicelqempmo3
rename lq_total_qtrly_wages servicelqwageqrtly
rename lq_taxable_qtrly_wages servicelqtaxwageqrtly
rename lq_qtrly_contributions servicecontriqrtly	
rename lq_avg_wkly_wage serviceavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2009service.dta , replace 
clear 

//*******************************************************************//
//********************************2010*******************************//
//*******************************************************************//

//*import 2010 all industries datafile*// 
	use Importable\2010allindustries.dta  

//*Drop Unneeded States*// 
drop if agglvl_code <=41
drop if agglvl_code >=80 & agglvl_code <=95
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

 //*Rename Variables*//
rename disclosure_code allindustriesdisclosurecode	 
rename qtrly_estabs_count allindustriesestablishments	
rename month1_emplvl allindustriesemploymentmo1	
rename month2_emplvl allindustriesemploymentmo2	
rename month3_emplvl allindustriesemploymentmo3
rename total_qtrly_wages allindustriestotalwages	
rename taxable_qtrly_wages allindustriestaxablewages
rename qtrly_contributions allindustriesqrtcontributions
rename avg_wkly_wage allindustriesavgwklywage
rename lq_disclosure_code allindustrieslqdisclosurecode	
rename lq_qtrly_estabs_count allindustrieslqempqrtly	
rename lq_month1_emplvl allindustrieslqempmo1
rename lq_month2_emplvl allindustrieslqempmo2
rename lq_month3_emplvl allindustrieslqempmo3
rename lq_total_qtrly_wages allindustrieslqwageqrtly
rename lq_taxable_qtrly_wages allindustrieslqtaxwageqrtly
rename lq_qtrly_contributions allindustriescontriqrtly	
rename lq_avg_wkly_wage allindustriesavgwkwageqrtly

//*Drop Unneeded Observations*//
generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

//*Save Dataset*//
save Merge\reduced2010allindustries.dta , replace 
clear 

//*******************************************************************//

//*import 2010 Coal Mining  datafile*// 
	use Importable\2010coal.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 46
drop if agglvl_code == 16
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*// 
rename qtrly_estabs_count coalestablishments	
rename month1_emplvl coalemploymentmo1	
rename month2_emplvl coalemploymentmo2	
rename month3_emplvl coalemploymentmo3
rename total_qtrly_wages coaltotalwages	
rename taxable_qtrly_wages coaltaxablewages
rename qtrly_contributions coalqrtcontributions
rename avg_wkly_wage coalavgwklywage
rename lq_disclosure_code coaldisclosurecode	
rename lq_qtrly_estabs_count coallqempqrtly	
rename lq_month1_emplvl	coallqempmo1
rename lq_month2_emplvl	coallqempmo2
rename lq_month3_emplvl	coallqempmo3
rename lq_total_qtrly_wages coallqwageqrtly
rename lq_taxable_qtrly_wages coallqtaxwageqrtly
rename lq_qtrly_contributions coalcontriqrtly	
rename lq_avg_wkly_wage coalavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 

//*Save Dataset*//
save Merge\reduced2010coalmining.dta , replace 
clear 

//*******************************************************************//

//*import 2010 Construction datafile*// 
	use Importable\2010construction.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count constructionestablishments	
rename month1_emplvl constructionemploymentmo1	
rename month2_emplvl constructionemploymentmo2	
rename month3_emplvl constructionemploymentmo3
rename total_qtrly_wages constructiontotalwages	
rename taxable_qtrly_wages constructiontaxablewages
rename qtrly_contributions constructionqrtcontributions
rename avg_wkly_wage constructionavgwklywage
rename lq_disclosure_code constructiondisclosurecode	
rename lq_qtrly_estabs_count constructionlqempqrtly	
rename lq_month1_emplvl constructionlqempmo1
rename lq_month2_emplvl constructionlqempmo2
rename lq_month3_emplvl constructionlqempmo3
rename lq_total_qtrly_wages constructionlqwageqrtly
rename lq_taxable_qtrly_wages constructionlqtaxwageqrtly
rename lq_qtrly_contributions constructioncontriqrtly	
rename lq_avg_wkly_wage constructionavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2010construction.dta , replace 
clear 

//*******************************************************************//

//*import 2010 Manufacturing datafile*// 
	use Importable\2010manufacturing.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count manufacturingestablishments	
rename month1_emplvl manufacturingemploymentmo1	
rename month2_emplvl manufacturingemploymentmo2	
rename month3_emplvl manufacturingemploymentmo3
rename total_qtrly_wages manufacturingtotalwages	
rename taxable_qtrly_wages manufacturingtaxablewages
rename qtrly_contributions manufacturingqrtcontributions
rename avg_wkly_wage manufacturingavgwklywage
rename lq_disclosure_code manufacturingdisclosurecode	
rename lq_qtrly_estabs_count manufacturinglqempqrtly	
rename lq_month1_emplvl manufacturinglqempmo1
rename lq_month2_emplvl manufacturinglqempmo2
rename lq_month3_emplvl manufacturinglqempmo3
rename lq_total_qtrly_wages manufacturinglqwageqrtly
rename lq_taxable_qtrly_wages manufacturinglqtaxwageqrtly
rename lq_qtrly_contributions manufacturingcontriqrtly	
rename lq_avg_wkly_wage manufacturingavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2010manufacturing.dta , replace 
clear 

//*******************************************************************//

//*import 2010 Retail Trade datafile*// 
	use Importable\2010retailtrade.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count retailtradeestablishments	
rename month1_emplvl retailtradeemploymentmo1	
rename month2_emplvl retailtradeemploymentmo2	
rename month3_emplvl retailtradeemploymentmo3
rename total_qtrly_wages retailtradetotalwages	
rename taxable_qtrly_wages retailtradetaxablewages
rename qtrly_contributions retailtradeqrtcontributions
rename avg_wkly_wage retailtradeavgwklywage
rename lq_disclosure_code retailtradedisclosurecode	
rename lq_qtrly_estabs_count retailtradelqempqrtly	
rename lq_month1_emplvl retailtradelqempmo1
rename lq_month2_emplvl retailtradelqempmo2
rename lq_month3_emplvl retailtradelqempmo3
rename lq_total_qtrly_wages retailtradelqwageqrtly
rename lq_taxable_qtrly_wages retailtradelqtaxwageqrtly
rename lq_qtrly_contributions retailtradecontriqrtly	
rename lq_avg_wkly_wage retailtradeavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2010retailtrade.dta , replace 
clear 

//*******************************************************************//

//*import 2010 Service Providing datafile*// 
	use Importable\2010service.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 42
drop if agglvl_code == 12
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count serviceestablishments	
rename month1_emplvl serviceemploymentmo1	
rename month2_emplvl serviceemploymentmo2	
rename month3_emplvl serviceemploymentmo3
rename total_qtrly_wages servicetotalwages	
rename taxable_qtrly_wages servicetaxablewages
rename qtrly_contributions serviceqrtcontributions
rename avg_wkly_wage serviceavgwklywage
rename lq_disclosure_code servicedisclosurecode	
rename lq_qtrly_estabs_count servicelqempqrtly	
rename lq_month1_emplvl servicelqempmo1
rename lq_month2_emplvl servicelqempmo2
rename lq_month3_emplvl servicelqempmo3
rename lq_total_qtrly_wages servicelqwageqrtly
rename lq_taxable_qtrly_wages servicelqtaxwageqrtly
rename lq_qtrly_contributions servicecontriqrtly	
rename lq_avg_wkly_wage serviceavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2010service.dta , replace 
clear 

//*******************************************************************//
//********************************2011*******************************//
//*******************************************************************//

//*import 2011 all industries datafile*// 
	use Importable\2011allindustries.dta  

//*Drop Unneeded States*// 
drop if agglvl_code <=41
drop if agglvl_code >=80 & agglvl_code <=95
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

 //*Rename Variables*//
rename disclosure_code allindustriesdisclosurecode	 
rename qtrly_estabs_count allindustriesestablishments	
rename month1_emplvl allindustriesemploymentmo1	
rename month2_emplvl allindustriesemploymentmo2	
rename month3_emplvl allindustriesemploymentmo3
rename total_qtrly_wages allindustriestotalwages	
rename taxable_qtrly_wages allindustriestaxablewages
rename qtrly_contributions allindustriesqrtcontributions
rename avg_wkly_wage allindustriesavgwklywage
rename lq_disclosure_code allindustrieslqdisclosurecode	
rename lq_qtrly_estabs_count allindustrieslqempqrtly	
rename lq_month1_emplvl allindustrieslqempmo1
rename lq_month2_emplvl allindustrieslqempmo2
rename lq_month3_emplvl allindustrieslqempmo3
rename lq_total_qtrly_wages allindustrieslqwageqrtly
rename lq_taxable_qtrly_wages allindustrieslqtaxwageqrtly
rename lq_qtrly_contributions allindustriescontriqrtly	
rename lq_avg_wkly_wage allindustriesavgwkwageqrtly

//*Drop Unneeded Observations*//
generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

//*Save Dataset*//
save Merge\reduced2011allindustries.dta , replace 
clear 

//*******************************************************************//

//*import 2011 Coal Mining  datafile*// 
	use Importable\2011coal.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 46
drop if agglvl_code == 16
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*// 
rename qtrly_estabs_count coalestablishments	
rename month1_emplvl coalemploymentmo1	
rename month2_emplvl coalemploymentmo2	
rename month3_emplvl coalemploymentmo3
rename total_qtrly_wages coaltotalwages	
rename taxable_qtrly_wages coaltaxablewages
rename qtrly_contributions coalqrtcontributions
rename avg_wkly_wage coalavgwklywage
rename lq_disclosure_code coaldisclosurecode	
rename lq_qtrly_estabs_count coallqempqrtly	
rename lq_month1_emplvl	coallqempmo1
rename lq_month2_emplvl	coallqempmo2
rename lq_month3_emplvl	coallqempmo3
rename lq_total_qtrly_wages coallqwageqrtly
rename lq_taxable_qtrly_wages coallqtaxwageqrtly
rename lq_qtrly_contributions coalcontriqrtly	
rename lq_avg_wkly_wage coalavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 

//*Save Dataset*//
save Merge\reduced2011coalmining.dta , replace 
clear 

//*******************************************************************//

//*import 2011 Construction datafile*// 
	use Importable\2011construction.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count constructionestablishments	
rename month1_emplvl constructionemploymentmo1	
rename month2_emplvl constructionemploymentmo2	
rename month3_emplvl constructionemploymentmo3
rename total_qtrly_wages constructiontotalwages	
rename taxable_qtrly_wages constructiontaxablewages
rename qtrly_contributions constructionqrtcontributions
rename avg_wkly_wage constructionavgwklywage
rename lq_disclosure_code constructiondisclosurecode	
rename lq_qtrly_estabs_count constructionlqempqrtly	
rename lq_month1_emplvl constructionlqempmo1
rename lq_month2_emplvl constructionlqempmo2
rename lq_month3_emplvl constructionlqempmo3
rename lq_total_qtrly_wages constructionlqwageqrtly
rename lq_taxable_qtrly_wages constructionlqtaxwageqrtly
rename lq_qtrly_contributions constructioncontriqrtly	
rename lq_avg_wkly_wage constructionavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2011construction.dta , replace 
clear 

//*******************************************************************//

//*import 2011 Manufacturing datafile*// 
	use Importable\2011manufacturing.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count manufacturingestablishments	
rename month1_emplvl manufacturingemploymentmo1	
rename month2_emplvl manufacturingemploymentmo2	
rename month3_emplvl manufacturingemploymentmo3
rename total_qtrly_wages manufacturingtotalwages	
rename taxable_qtrly_wages manufacturingtaxablewages
rename qtrly_contributions manufacturingqrtcontributions
rename avg_wkly_wage manufacturingavgwklywage
rename lq_disclosure_code manufacturingdisclosurecode	
rename lq_qtrly_estabs_count manufacturinglqempqrtly	
rename lq_month1_emplvl manufacturinglqempmo1
rename lq_month2_emplvl manufacturinglqempmo2
rename lq_month3_emplvl manufacturinglqempmo3
rename lq_total_qtrly_wages manufacturinglqwageqrtly
rename lq_taxable_qtrly_wages manufacturinglqtaxwageqrtly
rename lq_qtrly_contributions manufacturingcontriqrtly	
rename lq_avg_wkly_wage manufacturingavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2011manufacturing.dta , replace 
clear 

//*******************************************************************//

//*import 2011 Retail Trade datafile*// 
	use Importable\2011retailtrade.dta 

//*Drop Unneeded States*// 
drop if agglvl_code == 44
drop if agglvl_code == 14
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count retailtradeestablishments	
rename month1_emplvl retailtradeemploymentmo1	
rename month2_emplvl retailtradeemploymentmo2	
rename month3_emplvl retailtradeemploymentmo3
rename total_qtrly_wages retailtradetotalwages	
rename taxable_qtrly_wages retailtradetaxablewages
rename qtrly_contributions retailtradeqrtcontributions
rename avg_wkly_wage retailtradeavgwklywage
rename lq_disclosure_code retailtradedisclosurecode	
rename lq_qtrly_estabs_count retailtradelqempqrtly	
rename lq_month1_emplvl retailtradelqempmo1
rename lq_month2_emplvl retailtradelqempmo2
rename lq_month3_emplvl retailtradelqempmo3
rename lq_total_qtrly_wages retailtradelqwageqrtly
rename lq_taxable_qtrly_wages retailtradelqtaxwageqrtly
rename lq_qtrly_contributions retailtradecontriqrtly	
rename lq_avg_wkly_wage retailtradeavgwkwageqrtly

//*Destring Industry Code*//
replace industry_code = subinstr(industry_code, "-","",.)  
destring industry_code, replace 

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2011retailtrade.dta , replace 
clear 

//*******************************************************************//

//*import 2011 Service Providing datafile*// 
	use Importable\2011service.dta  

//*Drop Unneeded States*// 
drop if agglvl_code == 42
drop if agglvl_code == 12
destring area_fips, replace 
drop if area_fips <=20999
drop if (area_fips >=22000 & area_fips <=38999) 
drop if (area_fips >=40000 & area_fips <=41999) 
drop if (area_fips >=44000 & area_fips <=53999) 
drop if (area_fips >=55000) 

//*Rename Variables*//
rename qtrly_estabs_count serviceestablishments	
rename month1_emplvl serviceemploymentmo1	
rename month2_emplvl serviceemploymentmo2	
rename month3_emplvl serviceemploymentmo3
rename total_qtrly_wages servicetotalwages	
rename taxable_qtrly_wages servicetaxablewages
rename qtrly_contributions serviceqrtcontributions
rename avg_wkly_wage serviceavgwklywage
rename lq_disclosure_code servicedisclosurecode	
rename lq_qtrly_estabs_count servicelqempqrtly	
rename lq_month1_emplvl servicelqempmo1
rename lq_month2_emplvl servicelqempmo2
rename lq_month3_emplvl servicelqempmo3
rename lq_total_qtrly_wages servicelqwageqrtly
rename lq_taxable_qtrly_wages servicelqtaxwageqrtly
rename lq_qtrly_contributions servicecontriqrtly	
rename lq_avg_wkly_wage serviceavgwkwageqrtly

//*Drop Unneeded Observations*//
drop if area_fips == 21999
drop if area_fips == 39999
drop if area_fips == 42999
drop if area_fips == 54999

tab disclosure_code
replace disclosure_code	 = subinstr(disclosure_code, "N","1",.) 
replace disclosure_code	 = subinstr(disclosure_code, "-","1",.) 
destring disclosure_code, replace force 
drop if disclosure_code == 1  

generate employercode = subinstr(own_title, "Federal Government","1",.) 
replace employercode = subinstr(employercode, "Local Government","2",.) 
replace employercode = subinstr(employercode, "Private","3",.) 
replace employercode = subinstr(employercode, "State Government","4",.) 
replace employercode = subinstr(employercode, "Total Covered","5",.) 
replace employercode = subinstr(employercode, "Total Government","6",.) 
destring employercode, replace 

drop if employercode == 1
drop if employercode == 2
drop if employercode == 4
drop if employercode == 5
drop if employercode == 6

//*Save Dataset*//
save Merge\reduced2011service.dta , replace 
clear

//*******************************************************************//
//**************************Unemployment Data************************//
//*******************************************************************//

//***************************State-Level Data************************//

//*WV*// 
//Import WV Unemployment Data*//
	use Importable\WVstateunemployment.dta

//*Drop Unneeded Years*//
drop if year == 2005 
drop if year == 2012 
drop if year == 2013 
drop if year == 2014 
drop if year == 2015 

//*Drop Unneeded Variables*//
keep year unemployment period 

//*Create Quarter Variable*//
generate qtr = subinstr(period, "Mar","1",.) 
replace qtr = subinstr(qtr, "Jun","2",.) 
replace qtr = subinstr(qtr, "Sep","3",.) 
replace qtr = subinstr(qtr, "Dec","4",.) 

//*Drop Unneeded Months*//
drop if qtr == "Jan" 
drop if qtr == "Feb" 
drop if qtr == "Apr"
drop if qtr == "May"
drop if qtr == "Jul"
drop if qtr == "Aug"
drop if qtr == "Oct"
drop if qtr == "Nov"

destring qtr, replace 
drop period 

//*Create Area_Fips Variables for Merging*//
generate area_fips = 54000 

//*Rename Unemployment Variable for Merging
rename unemployment unemployed

//*Save Dataset*//
save Merge\unemploymentWVstate.dta, replace 
clear 

//*KY*// 
//Import WV Unemployment Data*//
	use Importable\KYstateunemployment.dta  

//*Drop Unneeded Years*//
drop if year == 2005 
drop if year == 2012 
drop if year == 2013 
drop if year == 2014 
drop if year == 2015 

//*Drop Unneeded Variables*//
keep year unemployment period 

//*Create Quarter Variable*//
generate qtr = subinstr(period, "Mar","1",.) 
replace qtr = subinstr(qtr, "Jun","2",.) 
replace qtr = subinstr(qtr, "Sep","3",.) 
replace qtr = subinstr(qtr, "Dec","4",.) 

//*Drop Unneeded Months*//
drop if qtr == "Jan" 
drop if qtr == "Feb" 
drop if qtr == "Apr"
drop if qtr == "May"
drop if qtr == "Jul"
drop if qtr == "Aug"
drop if qtr == "Oct"
drop if qtr == "Nov"

destring qtr, replace 
drop period 

//*Create Area_Fips Variables for Merging*//
generate area_fips = 21000 

//*Rename Unemployment Variable for Merging
rename unemployment unemployed 

//*Save Dataset*//
save Merge\unemploymentKYstate.dta, replace 
clear 

//**************************County-Level Data************************//


//*West Virginia*// 
//*Import Dataset*// 
	use Importable\WVcountyunemployment.dta 

//*Drop Unneeded Year*// 
keep if year == 2006 | year == 2007 | year == 2008 | year == 2009 | year == 2010 | year == 2011

//*Destring Month Variable*//
destring period, replace ignore ("M") 

//*Only Keep Unemployment Numbers*//
generate id2 = regexm(series_id, "000004")
drop if id2 == 0

//*Only Keep County Level Data*//
generate id3 = regexm(series_id, "CN")
drop if id3 == 0

//*Remove Zeros in ID Code to Isolate Area_Fips Code*//	
generate id = subinstr(series_id, "0000000004","",.) 

generate area_fips = subinstr(id, "LAUCN","",.) 
destring area_fips, replace 

//*Keep Needed Variables*//
keep value year period area_fips footnote_codes

//*Create Quarter Variable*//
drop if period == 1 
drop if period == 2 
drop if period == 4 
drop if period == 5 
drop if period == 7 
drop if period == 8 
drop if period == 10 
drop if period == 11
drop if period == 13  

generate qtr = 1 if period == 3 
replace qtr = 2 if period == 6 
replace qtr = 3 if period == 9 
replace qtr = 4 if period == 12 

//*Drop Unneeded Variables for Merging*//
drop period footnote_codes 

//*Rename Unemployment Variable*// 
rename value unemployed 

sort area_fips year qtr

//*Save Dataset*// 
save Merge\unemploymentWVcounty.dta, replace 
clear 

//*Kentucky*// 
//*Import Dataset*// 
	use Importable\KYcountyunemployment.dta

//*Drop Unneeded Year*// 
keep if year == 2006 | year == 2007 | year == 2008 | year == 2009 | year == 2010 | year == 2011

//*Destring Month Variable*//
destring period, replace ignore ("M") 


//*Only Keep Unemployment Numbers*//
generate id2 = regexm(series_id, "000004")
drop if id2 == 0

//*Only Keep County Level Data*//
generate id3 = regexm(series_id, "CN")
drop if id3 == 0

//*Remove Zeros in ID Code to Isolate Area_Fips Code*//	
generate id = subinstr(series_id, "0000000004","",.) 

generate area_fips = subinstr(id, "LAUCN","",.) 
destring area_fips, replace 

//*Keep Needed Variables*//
keep value year period area_fips footnote_codes

//*Create Quarter Variable*//
drop if period == 1 
drop if period == 2 
drop if period == 4 
drop if period == 5 
drop if period == 7 
drop if period == 8 
drop if period == 10 
drop if period == 11
drop if period == 13  

generate qtr = 1 if period == 3 
replace qtr = 2 if period == 6 
replace qtr = 3 if period == 9 
replace qtr = 4 if period == 12 

//*Drop Unneeded Variables for Merging*//
drop period footnote_codes 

//*Rename Unemployment Variable*// 
rename value unemployed 

sort area_fips year qtr

//*Save Dataset*// 
save Merge\unemploymentKYcounty.dta, replace 
clear 

//*******************************************************************//
//*******************************************************************//
//**************************Merging Datasets*************************//
//*******************************************************************//
//*******************************************************************//

//*******************************************************************//
//*************Merging Employment Together For Each Year*************//
//*******************************************************************//

//*******************************************************************//
//********************************2006*******************************//
//*******************************************************************//

use Merge\reduced2006allindustries.dta
	merge 1:1 area_fips qtr  using Merge\reduced2006coalmining.dta 
		rename _merge merge1
	merge 1:m area_fips qtr  using Merge\reduced2006construction.dta
		rename _merge merge2
	merge 1:m area_fips qtr  using Merge\reduced2006manufacturing.dta
		rename _merge merge3 
	merge 1:m area_fips qtr  using Merge\reduced2006retailtrade.dta
		rename _merge merge4
	merge 1:m area_fips qtr  using Merge\reduced2006service.dta
		rename _merge merge5 

	save Merge\2006mergedata.dta, replace 
	clear 

//*******************************************************************//
//********************************2007*******************************//
//*******************************************************************//

use Merge\reduced2007allindustries.dta
	merge 1:m area_fips qtr using Merge\reduced2007coalmining.dta 
		rename _merge merge1
	merge 1:m area_fips qtr using Merge\reduced2007construction.dta
		rename _merge merge2
	merge 1:m area_fips qtr using Merge\reduced2007manufacturing.dta
		rename _merge merge3 
	merge 1:m area_fips qtr using Merge\reduced2007retailtrade.dta
		rename _merge merge4
	merge 1:m area_fips qtr using Merge\reduced2007service.dta
		rename _merge merge5 

	save Merge\2007mergedata.dta, replace 
	clear 

//*******************************************************************//
//********************************2008*******************************//
//*******************************************************************//

use Merge\reduced2008allindustries.dta
	merge 1:m area_fips qtr  using Merge\reduced2008coalmining.dta 
		rename _merge merge1
	merge 1:m area_fips qtr  using Merge\reduced2008construction.dta
		rename _merge merge2
	merge 1:m area_fips qtr  using Merge\reduced2008manufacturing.dta
		rename _merge merge3 
	merge 1:m area_fips qtr  using Merge\reduced2008retailtrade.dta
		rename _merge merge4
	merge 1:m area_fips qtr  using Merge\reduced2008service.dta
		rename _merge merge5 

	save Merge\2008mergedata.dta, replace 
	clear 

//*******************************************************************//
//********************************2009*******************************//
//*******************************************************************//

use Merge\reduced2009allindustries.dta
	merge 1:m area_fips qtr  using Merge\reduced2009coalmining.dta 
		rename _merge merge1
	merge 1:m area_fips qtr  using Merge\reduced2009construction.dta
		rename _merge merge2
	merge 1:m area_fips qtr  using Merge\reduced2009manufacturing.dta
		rename _merge merge3 
	merge 1:m area_fips qtr  using Merge\reduced2009retailtrade.dta
		rename _merge merge4
	merge 1:m area_fips qtr  using Merge\reduced2009service.dta
		rename _merge merge5 

	save Merge\2009mergedata.dta, replace 
	clear 

//*******************************************************************//
//********************************2010*******************************//
//*******************************************************************//

use Merge\reduced2010allindustries.dta
	merge 1:m area_fips qtr  using Merge\reduced2010coalmining.dta 
		rename _merge merge1
	merge 1:m area_fips qtr  using Merge\reduced2010construction.dta
		rename _merge merge2
	merge 1:m area_fips qtr  using Merge\reduced2010manufacturing.dta
		rename _merge merge3 
	merge 1:m area_fips qtr  using Merge\reduced2010retailtrade.dta
		rename _merge merge4
	merge 1:m area_fips qtr  using Merge\reduced2010service.dta
		rename _merge merge5 

	save Merge\2010mergedata.dta, replace 
	clear 

//*******************************************************************//
//********************************2011*******************************//
//*******************************************************************//

use Merge\reduced2011allindustries.dta
	merge 1:m area_fips qtr  using Merge\reduced2011coalmining.dta 
		rename _merge merge1
	merge 1:m area_fips qtr  using Merge\reduced2011construction.dta
		rename _merge merge2
	merge 1:m area_fips qtr  using Merge\reduced2011manufacturing.dta
		rename _merge merge3 
	merge 1:m area_fips qtr  using Merge\reduced2011retailtrade.dta
		rename _merge merge4
	merge 1:m area_fips qtr  using Merge\reduced2011service.dta
		rename _merge merge5 

	save Merge\2011mergedata.dta, replace 
	clear 


//*******************************************************************//
//*****************Appending All Years Into One Dataset**************//
//*******************************************************************//

//*Merging Years*//
use Merge\2006mergedata.dta 
	append using Merge\2007mergedata.dta 
	append using Merge\2008mergedata.dta
	append using Merge\2009mergedata.dta
	append using Merge\2010mergedata.dta 
	append using Merge\2011mergedata.dta
	save Merge\Emplmergedata.dta, replace 
	clear

//*******************************************************************//
//*Merging Mine, Census and Unmployment Data With Employment Dataset*//
//*******************************************************************//
	
//*************************Merging Coal Data*************************//	
use Merge\Emplmergedata.dta
	merge m:1 area_fips using Merge\reducedminecount.dta
		rename _merge merge9 
	save Merge\finalmergedata1.dta, replace 
	clear 

//******************Merging County Female/Male Pop Data**************//	
use Merge\reducedcensus.dta 

//*Combining Age Groups into One Variable*//
generate Femalepop2006 = Fpopestimate2006_20_24 + Fpopestimate2006_25_29 + Fpopestimate2006_30_34 + Fpopestimate2006_35_39 + Fpopestimate2006_40_44 + Fpopestimate2006_45_49 + Fpopestimate2006_50_54 + Fpopestimate2006_55_59 + Fpopestimate2006_60_64 + Fpopestimate2006_65_69
generate Femalepop2007 = Fpopestimate2007_20_24 + Fpopestimate2007_25_29 + Fpopestimate2007_30_34 + Fpopestimate2007_35_39 + Fpopestimate2007_40_44 + Fpopestimate2007_45_49 + Fpopestimate2007_50_54 + Fpopestimate2007_55_59 + Fpopestimate2007_60_64 + Fpopestimate2007_65_69
generate Femalepop2008 = Fpopestimate2008_20_24 + Fpopestimate2008_25_29 + Fpopestimate2008_30_34 + Fpopestimate2008_35_39 + Fpopestimate2008_40_44 + Fpopestimate2008_45_49 + Fpopestimate2008_50_54 + Fpopestimate2008_55_59 + Fpopestimate2008_60_64 + Fpopestimate2008_65_69
generate Femalepop2009 = Fpopestimate2009_20_24 + Fpopestimate2009_25_29 + Fpopestimate2009_30_34 + Fpopestimate2009_35_39 + Fpopestimate2009_40_44 + Fpopestimate2009_45_49 + Fpopestimate2009_50_54 + Fpopestimate2009_55_59 + Fpopestimate2009_60_64 + Fpopestimate2009_65_69
generate Femalepop2010 = Fpopestimate2010_20_24 + Fpopestimate2010_25_29 + Fpopestimate2010_30_34 + Fpopestimate2010_35_39 + Fpopestimate2010_40_44 + Fpopestimate2010_45_49 + Fpopestimate2010_50_54 + Fpopestimate2010_55_59 + Fpopestimate2010_60_64 + Fpopestimate2010_65_69
generate Femalepop2011 = Fpopestimate2011_20_24 + Fpopestimate2011_25_29 + Fpopestimate2011_30_34 + Fpopestimate2011_35_39 + Fpopestimate2011_40_44 + Fpopestimate2011_45_49 + Fpopestimate2011_50_54 + Fpopestimate2011_55_59 + Fpopestimate2011_60_64 + Fpopestimate2011_65_69

generate Malepop2006 = Mpopestimate2006_20_24 + Mpopestimate2006_25_29 + Mpopestimate2006_30_34 + Mpopestimate2006_35_39 + Mpopestimate2006_40_44 + Mpopestimate2006_45_49 + Mpopestimate2006_50_54 + Mpopestimate2006_55_59 + Mpopestimate2006_60_64 + Mpopestimate2006_65_69
generate Malepop2007 = Mpopestimate2007_20_24 + Mpopestimate2007_25_29 + Mpopestimate2007_30_34 + Mpopestimate2007_35_39 + Mpopestimate2007_40_44 + Mpopestimate2007_45_49 + Mpopestimate2007_50_54 + Mpopestimate2007_55_59 + Mpopestimate2007_60_64 + Mpopestimate2007_65_69
generate Malepop2008 = Mpopestimate2008_20_24 + Mpopestimate2008_25_29 + Mpopestimate2008_30_34 + Mpopestimate2008_35_39 + Mpopestimate2008_40_44 + Mpopestimate2008_45_49 + Mpopestimate2008_50_54 + Mpopestimate2008_55_59 + Mpopestimate2008_60_64 + Mpopestimate2008_65_69
generate Malepop2009 = Mpopestimate2009_20_24 + Mpopestimate2009_25_29 + Mpopestimate2009_30_34 + Mpopestimate2009_35_39 + Mpopestimate2009_40_44 + Mpopestimate2009_45_49 + Mpopestimate2009_50_54 + Mpopestimate2009_55_59 + Mpopestimate2009_60_64 + Mpopestimate2009_65_69
generate Malepop2010 = Mpopestimate2010_20_24 + Mpopestimate2010_25_29 + Mpopestimate2010_30_34 + Mpopestimate2010_35_39 + Mpopestimate2010_40_44 + Mpopestimate2010_45_49 + Mpopestimate2010_50_54 + Mpopestimate2010_55_59 + Mpopestimate2010_60_64 + Mpopestimate2010_65_69
generate Malepop2011 = Mpopestimate2011_20_24 + Mpopestimate2011_25_29 + Mpopestimate2011_30_34 + Mpopestimate2011_35_39 + Mpopestimate2011_40_44 + Mpopestimate2011_45_49 + Mpopestimate2011_50_54 + Mpopestimate2011_55_59 + Mpopestimate2011_60_64 + Mpopestimate2011_65_69

//*Keep Combined Age Variables*//
keep area_fips Malepop2006 Femalepop2006 Malepop2007 Femalepop2007 Malepop2008 Femalepop2008 Malepop2009 Femalepop2009 Malepop2010 Femalepop2010 Malepop2011 Femalepop2011

//*Save Dataset*//
save Merge\reducedcensusMF.dta , replace 
clear 

//*Divide Populatation Data By Year*//

//*2006*//
use Merge\reducedcensusMF.dta 
keep area_fips Malepop2006 Femalepop2006 
generate year = 2006
rename Malepop2006  Malepop
rename Femalepop2006  Femalepop
save Merge\reducedcensusMF2006.dta , replace 
clear 

//*2007*//
use Merge\reducedcensusMF.dta 
keep area_fips Malepop2007 Femalepop2007 
generate year = 2007
rename Malepop2007  Malepop
rename Femalepop2007  Femalepop
save Merge\reducedcensusMF2007.dta , replace 
clear 

//*2008*//
use Merge\reducedcensusMF.dta 
keep area_fips Malepop2008 Femalepop2008 
generate year = 2008
rename Malepop2008  Malepop
rename Femalepop2008  Femalepop
save Merge\reducedcensusMF2008.dta , replace 
clear 

//*2009*//
use Merge\reducedcensusMF.dta 
keep area_fips Malepop2009 Femalepop2009 
generate year = 2009
rename Malepop2009  Malepop
rename Femalepop2009  Femalepop
save Merge\reducedcensusMF2009.dta , replace 
clear 

//*2010*//
use Merge\reducedcensusMF.dta 
keep area_fips Malepop2010 Femalepop2010 
generate year = 2010
rename Malepop2010  Malepop
rename Femalepop2010  Femalepop
save Merge\reducedcensusMF2010.dta , replace 
clear 

//*2011*//
use Merge\reducedcensusMF.dta 
keep area_fips Malepop2011 Femalepop2011 
generate year = 2011
rename Malepop2011  Malepop
rename Femalepop2011  Femalepop
save Merge\reducedcensusMF2011.dta , replace 
clear 

//*Append Each Year Into One Dataset*//
use Merge\reducedcensusMF2006.dta
	append using Merge\reducedcensusMF2007.dta 
	append using Merge\reducedcensusMF2008.dta
	append using Merge\reducedcensusMF2009.dta
	append using Merge\reducedcensusMF2010.dta
	append using Merge\reducedcensusMF2011.dta
	sort area_fips year 
save Merge\reducedmergepopMF , replace 
clear 

//********************Merging State Female/Male Pop Data***************//	

use Merge\reducedcensusstate.dta 

//*Combining Age Groups into One Variable*//
generate Femalepop2006 = Fpopestimate2006_20_24 + Fpopestimate2006_25_29 + Fpopestimate2006_30_34 + Fpopestimate2006_35_39 + Fpopestimate2006_40_44 + Fpopestimate2006_45_49 + Fpopestimate2006_50_54 + Fpopestimate2006_55_59 + Fpopestimate2006_60_64 + Fpopestimate2006_65_69
generate Femalepop2007 = Fpopestimate2007_20_24 + Fpopestimate2007_25_29 + Fpopestimate2007_30_34 + Fpopestimate2007_35_39 + Fpopestimate2007_40_44 + Fpopestimate2007_45_49 + Fpopestimate2007_50_54 + Fpopestimate2007_55_59 + Fpopestimate2007_60_64 + Fpopestimate2007_65_69
generate Femalepop2008 = Fpopestimate2008_20_24 + Fpopestimate2008_25_29 + Fpopestimate2008_30_34 + Fpopestimate2008_35_39 + Fpopestimate2008_40_44 + Fpopestimate2008_45_49 + Fpopestimate2008_50_54 + Fpopestimate2008_55_59 + Fpopestimate2008_60_64 + Fpopestimate2008_65_69
generate Femalepop2009 = Fpopestimate2009_20_24 + Fpopestimate2009_25_29 + Fpopestimate2009_30_34 + Fpopestimate2009_35_39 + Fpopestimate2009_40_44 + Fpopestimate2009_45_49 + Fpopestimate2009_50_54 + Fpopestimate2009_55_59 + Fpopestimate2009_60_64 + Fpopestimate2009_65_69
generate Femalepop2010 = Fpopestimate2010_20_24 + Fpopestimate2010_25_29 + Fpopestimate2010_30_34 + Fpopestimate2010_35_39 + Fpopestimate2010_40_44 + Fpopestimate2010_45_49 + Fpopestimate2010_50_54 + Fpopestimate2010_55_59 + Fpopestimate2010_60_64 + Fpopestimate2010_65_69

generate Malepop2006 = Mpopestimate2006_20_24 + Mpopestimate2006_25_29 + Mpopestimate2006_30_34 + Mpopestimate2006_35_39 + Mpopestimate2006_40_44 + Mpopestimate2006_45_49 + Mpopestimate2006_50_54 + Mpopestimate2006_55_59 + Mpopestimate2006_60_64 + Mpopestimate2006_65_69
generate Malepop2007 = Mpopestimate2007_20_24 + Mpopestimate2007_25_29 + Mpopestimate2007_30_34 + Mpopestimate2007_35_39 + Mpopestimate2007_40_44 + Mpopestimate2007_45_49 + Mpopestimate2007_50_54 + Mpopestimate2007_55_59 + Mpopestimate2007_60_64 + Mpopestimate2007_65_69
generate Malepop2008 = Mpopestimate2008_20_24 + Mpopestimate2008_25_29 + Mpopestimate2008_30_34 + Mpopestimate2008_35_39 + Mpopestimate2008_40_44 + Mpopestimate2008_45_49 + Mpopestimate2008_50_54 + Mpopestimate2008_55_59 + Mpopestimate2008_60_64 + Mpopestimate2008_65_69
generate Malepop2009 = Mpopestimate2009_20_24 + Mpopestimate2009_25_29 + Mpopestimate2009_30_34 + Mpopestimate2009_35_39 + Mpopestimate2009_40_44 + Mpopestimate2009_45_49 + Mpopestimate2009_50_54 + Mpopestimate2009_55_59 + Mpopestimate2009_60_64 + Mpopestimate2009_65_69
generate Malepop2010 = Mpopestimate2010_20_24 + Mpopestimate2010_25_29 + Mpopestimate2010_30_34 + Mpopestimate2010_35_39 + Mpopestimate2010_40_44 + Mpopestimate2010_45_49 + Mpopestimate2010_50_54 + Mpopestimate2010_55_59 + Mpopestimate2010_60_64 + Mpopestimate2010_65_69

//*Keep Combined Age Variables*//
keep area_fips Malepop2006 Femalepop2006 Malepop2007 Femalepop2007 Malepop2008 Femalepop2008 Malepop2009 Femalepop2009 Malepop2010 Femalepop2010 Malepop2011 Femalepop2011

//*Save Dataset*//
save Merge\reducedcensusstateMF.dta , replace 
clear 

//*Divide Populatation Data By Year*//

//*2006*//
use Merge\reducedcensusstateMF.dta 
keep area_fips Malepop2006 Femalepop2006 
generate year = 2006
rename Malepop2006  Malepop
rename Femalepop2006  Femalepop
save Merge\reducedcensusstateMF2006.dta , replace 
clear 

//*2007*//
use Merge\reducedcensusstateMF.dta 
keep area_fips Malepop2007 Femalepop2007 
generate year = 2007
rename Malepop2007  Malepop
rename Femalepop2007  Femalepop
save Merge\reducedcensusstateMF2007.dta , replace 
clear 

//*2008*//
use Merge\reducedcensusstateMF.dta 
keep area_fips Malepop2008 Femalepop2008 
generate year = 2008
rename Malepop2008  Malepop
rename Femalepop2008  Femalepop
save Merge\reducedcensusstateMF2008.dta , replace 
clear 

//*2009*//
use Merge\reducedcensusstateMF.dta 
keep area_fips Malepop2009 Femalepop2009 
generate year = 2009
rename Malepop2009  Malepop
rename Femalepop2009  Femalepop
save Merge\reducedcensusstateMF2009.dta , replace 
clear 

//*2010*//
use Merge\reducedcensusstateMF.dta 
keep area_fips Malepop2010 Femalepop2010 
generate year = 2010
rename Malepop2010  Malepop
rename Femalepop2010  Femalepop
save Merge\reducedcensusstateMF2010.dta , replace 
clear 

//*2011*//
use Merge\reducedcensusstateMF.dta 
keep area_fips Malepop2011 Femalepop2011 
generate year = 2011
rename Malepop2011  Malepop
rename Femalepop2011  Femalepop
save Merge\reducedcensusstateMF2011.dta , replace 
clear 

//*Append Each Year Into One Dataset*//
use Merge\reducedcensusstateMF2006.dta
	append using Merge\reducedcensusstateMF2007.dta 
	append using Merge\reducedcensusstateMF2008.dta
	append using Merge\reducedcensusstateMF2009.dta
	append using Merge\reducedcensusstateMF2010.dta
	append using Merge\reducedcensusstateMF2011.dta
	sort area_fips year 
save Merge\reducedstatemergepopMF , replace 
clear 

//*Adding State Data to County Level Data*//
use Merge\reducedmergepopMF.dta 
	append using Merge\reducedstatemergepopMF
	sort area_fips year 
save Merge\reducedcountystatepop.dta, replace 
clear 
	
//**********Merging Population Data with Employment Data*************//
use Merge\finalmergedata1.dta

//*2006 Total Population Data*//
	merge m:1 area_fips using Merge\2006pop.dta
		rename _merge merge30
		
//*State and County Level Population Data*//
	merge m:1 area_fips year using Merge\reducedcountystatepop.dta
		rename _merge merge33
		
//*Save Dataset*//
	save Merge\finalmergedata2.dta, replace 
	clear 
	
//*******************************************************************//
//************************Merging Unemployment***********************//
//*******************************************************************//

//*Combing State WV and KY Unemployment Data*//
use Merge\unemploymentWVstate.dta 
	append using Merge\unemploymentKYstate.dta 
	append using Merge\unemploymentWVcounty.dta 
	append using Merge\unemploymentKYcounty.dta 
	sort area_fips year qtr
save Merge\mergeunemployment.dta, replace 
clear 

//**********Creating State Groups to Merge Unemployment***************//
use Merge\finalmergedata2.dta

//*Merge Unemployment Data with Employment Data*//
merge 1:1 area_fips year qtr using Merge\mergeunemployment.dta
	rename _merge merge34
	sort area_fips year qtr 

//*Save Merged Dataset*//
save Merge\finalmergedata.dta , replace 
clear 


